Skip to content

Instantly share code, notes, and snippets.

@jonalmeida
Created April 28, 2016 23:45
Show Gist options
  • Save jonalmeida/cb605a5f4e8707d13a24353eaf7ab54f to your computer and use it in GitHub Desktop.
Save jonalmeida/cb605a5f4e8707d13a24353eaf7ab54f to your computer and use it in GitHub Desktop.
src/lib.rs:27:28: 27:32 error: `name` does not live long enough
src/lib.rs:27 let name_str = name.as_str();
^~~~
src/lib.rs:24:37: 36: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 uuid = Uuid::new_v4();
src/lib.rs:26 let name = uuid.to_string();
src/lib.rs:27 let name_str = name.as_str();
src/lib.rs:28 let mut clocks = HashMap::new();
src/lib.rs:29 clocks.insert(name_str, 0);
...
src/lib.rs:26:41: 36:6 note: ...but borrowed value is only valid for the block suffix following statement 1 at 26:40
src/lib.rs:26 let name = uuid.to_string();
src/lib.rs:27 let name_str = name.as_str();
src/lib.rs:28 let mut clocks = HashMap::new();
src/lib.rs:29 clocks.insert(name_str, 0);
src/lib.rs:30
src/lib.rs:31 Client {
...
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 uuid = Uuid::new_v4();
let name = uuid.to_string();
let name_str = name.as_str();
let mut clocks = HashMap::new();
clocks.insert(name_str, 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