Function plain::as_bytes
[−]
[src]
pub fn as_bytes<S: ?Sized>(s: &S) -> &[u8] where S:
Safely converts a reference to any type to an immutable byte slice of appropriate length.
Since the result can't be used to modify the source structure, this is perfectly safe to do on any type, even if mostly useless for most Rust types.
This function cannot fail.
Beware: Types that are not #repr(C) mostly have
unspecified layout, and in fact can even change
layout from build to build. Two types with exactly
same definition can even have different layout in
the same build!
It's perfectly safe to read the data and e.g.
print it on screen for educational value, but
interpreting the data to mean anything is bound
to cause bugs. #repr(C) structures don't have
this problem as their layout is perfectly well
defined.