Created
August 12, 2014 06:15
-
-
Save shadowmint/8b1811d1bf0afffc53d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src/string.rs:371:3: 379:4 note: consider using an explicit lifetime parameter as shown: fn clone(&self) -> String<'a> | |
src/string.rs:371 fn clone(&self) -> String<'b> { | |
src/string.rs:372 return String { | |
src/string.rs:373 len: self.len, | |
src/string.rs:374 bytes: match self.bytes { | |
src/string.rs:375 IsStatic(ref x) => IsStatic(x.as_array().clone()), | |
src/string.rs:376 IsView(ref x) => IsStatic(x.as_array().clone()) | |
... | |
src/string.rs:371:3: 379:4 error: method not compatible with trait: expected `fn(&string::String<'a>) -> string::String<'a>` but found `fn(&string::String<'a>) -> string::String<'b>` (lifetime mismatch) | |
src/string.rs:371 fn clone(&self) -> String<'b> { | |
src/string.rs:372 return String { | |
src/string.rs:373 len: self.len, | |
src/string.rs:374 bytes: match self.bytes { | |
src/string.rs:375 IsStatic(ref x) => IsStatic(x.as_array().clone()), | |
src/string.rs:376 IsView(ref x) => IsStatic(x.as_array().clone()) | |
... | |
error: aborting due to previous error | |
Build failed, waiting for other jobs to finish... | |
src/string.rs:371:3: 379:4 note: consider using an explicit lifetime parameter as shown: fn clone(&self) -> String<'a> | |
src/string.rs:371 fn clone(&self) -> String<'b> { | |
src/string.rs:372 return String { | |
src/string.rs:373 len: self.len, | |
src/string.rs:374 bytes: match self.bytes { | |
src/string.rs:375 IsStatic(ref x) => IsStatic(x.as_array().clone()), | |
src/string.rs:376 IsView(ref x) => IsStatic(x.as_array().clone()) | |
... | |
src/string.rs:371:3: 379:4 error: method not compatible with trait: expected `fn(&string::String<'a>) -> string::String<'a>` but found `fn(&string::String<'a>) -> string::String<'b>` (lifetime mismatch) | |
src/string.rs:371 fn clone(&self) -> String<'b> { | |
src/string.rs:372 return String { | |
src/string.rs:373 len: self.len, | |
src/string.rs:374 bytes: match self.bytes { | |
src/string.rs:375 IsStatic(ref x) => IsStatic(x.as_array().clone()), | |
src/string.rs:376 IsView(ref x) => IsStatic(x.as_array().clone()) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Possible string implementations | |
enum StringType<U, V> { | |
IsStatic(U), | |
IsView(V) | |
} | |
/// An alternative utf8-ish string type. | |
/// Graphemes are packed with a leading u8 length byte. | |
/// Although this is less efficient for storage of long strings, | |
/// it has a number of very useful properties, particularly that | |
/// String is indexable with the type Rune. | |
pub struct String<'a> { | |
len:uint, | |
bytes:StringType<Static<u8>, View<'a, u8>> | |
} | |
... | |
/// Deep clone the memory for this string. | |
impl<'a> Clone for String<'a> { | |
fn clone(&self) -> String<'b> { | |
return String { | |
len: self.len, | |
bytes: match self.bytes { | |
IsStatic(ref x) => IsStatic(x.as_array().clone()), // Copies inner bytes | |
IsView(ref x) => IsStatic(x.as_array().clone()) // Copies inner bytes | |
} | |
}; | |
} | |
fn clone_from(&mut self, source:&String) { | |
self.len = source.len; | |
self.bytes = match source.bytes { | |
IsStatic(ref x) => IsStatic(x.as_array().clone()), | |
IsView(ref x) => IsStatic(x.as_array().clone()) | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment