Skip to content

Instantly share code, notes, and snippets.

@jonalmeida
Last active April 28, 2016 23:37
Show Gist options
  • Save jonalmeida/0e057dc18f832e11394f8dceb216bbca to your computer and use it in GitHub Desktop.
Save jonalmeida/0e057dc18f832e11394f8dceb216bbca to your computer and use it in GitHub Desktop.
src/lib.rs:25:25: 25:51 error: borrowed value does not live long enough
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
^~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:24:37: 34:6 note: reference must be valid for the lifetime 'a as defined on the block at 24:36...
src/lib.rs:24 where T: Into<Cow<'a, str>> {
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
src/lib.rs:26 let mut clocks = HashMap::new();
src/lib.rs:27 clocks.insert(name, 0);
src/lib.rs:28
src/lib.rs:29 Client {
...
src/lib.rs:25:13: 25:61 note: ...but borrowed value is only valid for the statement at 25:12
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:25:13: 25:61 help: consider using a `let` binding to increase its lifetime
src/lib.rs:25 let name = Uuid::new_v4().to_string().as_str();
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pub struct Client<'a> {
pub name: &'a str,
pub addr: Cow<'a, str>,
clocks: HashMap<&'a str, u32>
}
impl<'a> Client<'a> {
pub fn new<T>(addr: T) -> Client<'a>
where T: Into<Cow<'a, str>> {
let name = Uuid::new_v4().to_string().as_str();
let mut clocks = HashMap::new();
clocks.insert(name, 0);
Client {
name: "foo",
addr: addr.into(),
clocks: clocks
}
}
pub fn connect(&self, peer: Client) -> Option<()> {
None
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment