Closed kurtlawrence closed 5 years ago
I believe I can use the current macro implementation. See the example below.
macro_rules! tst {
(&mut $type:ty) => {{
println!("a mutable reference type");
stringify!($type)
}};
(&$type:ty) => {{
println!("a reference type");
stringify!($type)
}};
($type:ty) => {{
println!("just a type");
stringify!($type)
}};
}
fn main() {
dbg!(tst!(String));
dbg!(tst!(&String));
dbg!(tst!(&mut String));
dbg!(tst!(&mut String));
dbg!(tst!(&&String));
dbg!(tst!(&mut &mut String));
}
Rust's macros can give me the information about reference type, by matching a pattern of &mut Type
or & Type
above just Type
. The system doesn't hold up well with double references. Might have to test that later.
fixed on dev branch
Mutably borrow types will not work with the current type system. This is because an
eval()
call will return aRepl
with a type parameter ofData
. If this type parameter is&mut
then the reference lifetime will follow through, such that once given some dataData
, rust thinks the lifetime is still valid for theRead
return value (as it is capturesData
as well).I will have to move back to typing the reference type,
NoRef
,Brw
, andBrwMut
.