pub struct FixStr(/* private fields */);
Implementations§
Source§impl FixStr
impl FixStr
Sourcepub const fn from_ascii(buf: &[u8]) -> Result<&FixStr, FixStringError>
pub const fn from_ascii(buf: &[u8]) -> Result<&FixStr, FixStringError>
Converts a slice of bytes to a string slice.
A FIX string slice (&FixStr
) is made of bytes (u8
), and a byte
slice (&[u8]
) is made of bytes, so this function
converts between the two. Not all byte slices are valid string slices,
however: &FixStr
requires that it is valid ASCII without controll
characters.
from_ascii()
checks to ensure that the bytes are valid, and then does
the conversion.
If you are sure that the byte slice is valid ASCII without controll
characters, and you don’t want to incur the overhead of the validity
check, there is an unsafe version of this function,
from_ascii_unchecked
, which has the same behavior but skips
the check.
If you need a FixString
instead of a &FixStr
, consider
FixString::from_ascii
.
Because you can stack-allocate a [u8; N]
, and you can take a
&[u8]
of it, this function is one way to have a
stack-allocated string.
§Errors
Returns Err
if the slice is not ASCII.
Sourcepub const unsafe fn from_ascii_unchecked(buf: &[u8]) -> &FixStr
pub const unsafe fn from_ascii_unchecked(buf: &[u8]) -> &FixStr
Converts a slice of bytes to a FIX string slice without checking that it contains only ASCII characters.
See the safe version, from_ascii
, for more information.
§Safety
The bytes passed in must consists from ASCII characters only.