This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
5
Graph implementation: pointer to arbitrary data type
Post Body
Hi, rust noob here.
I'm trying to implement a graph in rust. I want each node to be able to hold an arbitrary data type. Here is the code I have so far:
pub struct Node<T> {
pub data: T,
pub adjacencyList: Vec<Node>,
}
///
let node1 = Node {
data: 5,
adjacencyList: Vec::new(),
};
let node2 = Node {
data: "six",
adjacencyList: Vec::new(),
};
node1.adjacencyList.push(node2);
obviously it doesn't work, but that's the gist of it. I want to be able to reference another node with an arbitrary data type. Is there a way to do this? I'm thinking I have to use raw pointers but not sure how to do that yet. Thanks.
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
41,838
Link Karma
1,826
Comment Karma
39,939
Profile updated: 1 day ago
Posts updated: 1 year ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/rust/commen...