pub struct FsString { /* private fields */ }
Expand description
A type that represents a mutable and owned VEXos filesystem string, while being cheaply inter-convertible with Rust strings.
FsString
is NOT null terminated. If you need to pass this to VEX SDK filesystem functions,
create a CStr
.
An FsString
is to &FsStr
as String
is to &str
;
the former are owned, while the latter are borrowed references.
Implementations§
Source§impl FsString
impl FsString
Sourcepub unsafe fn from_encoded_bytes_unchecked(bytes: Vec<u8>) -> Self
pub unsafe fn from_encoded_bytes_unchecked(bytes: Vec<u8>) -> Self
Sourcepub fn into_encoded_bytes(self) -> Vec<u8>
pub fn into_encoded_bytes(self) -> Vec<u8>
Returns the raw encoded bytes of the FsString
Sourcepub fn into_string(self) -> Result<String, FsString>
pub fn into_string(self) -> Result<String, FsString>
Sourcepub fn push<S: AsRef<FsStr>>(&mut self, s: S)
pub fn push<S: AsRef<FsStr>>(&mut self, s: S)
Extends the FsString
with the given string.
As an example, the stored data in this example will be equivalent to “foobarbaz”:
let mut foo = FsString::new();
foo.push("foo");
foo.push("bar");
foo.push("baz");
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new FsString
with the given capacity.
For more information on capacity, look at the Vec::with_capacity
documentation.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of the FsString
.
The capacity of the string will be equivalent to the maximum number of characters unless special characters are used.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves at least additional
bytes in the FsString
.
In order to reduce allocations, this function will often reserve more than additional
bytes.
For more information on the logic behind reserving bytes, see the Vec::reserve
documentation.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
Attempts to reserve at least additional
bytes in the FsString
.
In order to reduce allocations, this function will often reserve more than additional
bytes.
For more information on the logic behind reserving bytes, see the Vec::reserve
documentation.
§Errors
This function will error under the following conditions:
- The capacity of the
FsString
has surpassesisize::MAX
bytes - An allocation error occured while reserving space.
Sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Reserves additional
bytes in the FsString
.
§Note
Reserving an exact amount of times can often negatively impact performace.
you most likely want to use FsString::reserve
Sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Attempts to reserve additional
bytes in the FsString
.
§Note
Reserving an exact amount of times can often negatively impact performace.
you most likely want to use FsString::reserve
§Errors
This function will error under the following conditions:
- The capacity of the
FsString
has surpassesisize::MAX
bytes - An allocation error occured while reserving space.
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the FsString
as much as possible.
Depending on the allocator implementation, the FsString
may still have extra capacity.
See core::alloc::Allocator::shrink
for more info.
Sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Shrinks the capacity of the FsString
to a lower bound.
Sourcepub fn into_boxed_fs_str(self) -> Box<FsStr>
pub fn into_boxed_fs_str(self) -> Box<FsStr>
Consumes and converts this FsString
into a Box<FsStr>
.
Excess capacity is discarded.
Methods from Deref<Target = FsStr>§
Sourcepub fn as_encoded_bytes(&self) -> &[u8]
pub fn as_encoded_bytes(&self) -> &[u8]
Converts an FS string slice to a byte slice. To convert the byte slice back into an FS
string slice, use the FsStr::from_encoded_bytes_unchecked
function.
§Note
As the encoding is unspecified, any sub-slice of bytes that is not valid UTF-8 should be treated as opaque and only comparable within the same Rust version built for the same target platform. For example, sending the slice over the network or storing it in a file will likely result in incompatible byte slices.
Sourcepub fn to_fs_string(&self) -> FsString
pub fn to_fs_string(&self) -> FsString
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Converts an FsStr
into a UTF-8 encoded string.
Any non-UTF-8 sequences are replaced with the unicode
U+FFFD REPLACEMENT CHARACTER
.