This is a two-parter.
Ideally I'd like to implement the FromStr trait, but with or without that, I need to implement from_str().
A CqlString consists of a u16 (two u8s) followed by the raw bytes of the original string.
The version below generates "error: 'bytes' does not live long enough", so that's problem #1.
If I make it "impl FromStr for CqlString", then I get an earlier error of:
error: method from_str
has an incompatible type for trait: expected concrete lifetime, found bound lifetime parameter [E0053]
So given the structure of CqlString, how can I implement a FromStr fn properly?
#[repr(C, packed)]
pub struct CqlString<'a>(&'a [u8]);
impl<'a> CqlString<'a> {
fn from_str(s: &str) -> Option<CqlString> {
let mut bytes = Vec::<u8>::new();
bytes.push_all(unsafe{Utils::raw_byte_repr(&s.len().to_u16())}); //convert the hashmap length to a a two byte short and start building our &[u8]
bytes.push_all(s.as_bytes());
let cqls = CqlString(bytes[]);
Some(cqls)
}
}