-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A unique string key for TypeId #694
Comments
|
We don't have a ton of labels yet. I want to triage everything first, and then plan on going through the wishlist label and adding stuff like easy/hard. |
Re-connecting to #664. |
I don't really understand this request. The |
What is wrong with just using the byte representation of the |
@thestinger As mentioned in the description, the integer may be good enough (though only available via |
Sadly, I don't think the way Rust produces the user-facing type strings results in unique names. |
use std::intrinsics::get_tydesc;
mod foo {
pub struct Baz;
}
fn foo() {
struct Baz;
unsafe {
println!("{}", (*get_tydesc::<Baz>()).name);
println!("{}", (*get_tydesc::<foo::Baz>()).name)
}
}
fn main() {
foo();
} |
At a minimum, Rust would need to consider functions as being module namespaces in order for the current names to be unique. |
In fact, it's easy to achieve both requirements on my side, by simply combining the hash and the human-readable name. It would still be nice to get the name safely available, though. |
In the end we increased the TypeId size to 128bit: rust-lang/rust#109953 Using strings didn't end up happening: rust-lang/rust#95845 |
Nothing prevents the string approach from happening in the future, that wasn't the intention of the size increase. |
Issue by mzabaluev
Tuesday Jan 13, 2015 at 22:40 GMT
For earlier discussion, see rust-lang/rust#21116
This issue was labelled with: A-libs, A-typesystem in the Rust repository
I want to implement a mapping of
Box<T: 'static>
to GType. That dynamic type system requires process-unique type names. So I'd like to have a process-unique key, preferably a string, available fromTypeId
or a similar API.Now, it's likely that
TyDesc
names are sufficiently unique, and hash collisions onTypeId
break the world as Rust knows it (#17179) so theu64
hash value can be used as practically unique, but: 1) uniqueness constraints on any of those are not documented; 2) access toTyDesc
is unsafe.The text was updated successfully, but these errors were encountered: