Skip to content

Commit 7e724d1

Browse files
committed
FileBuf.into
1 parent 99704f9 commit 7e724d1

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "firefly-rust"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
edition = "2021"
55
rust-version = "1.81.0"
66
authors = ["Firefly Zero team"]

src/fs.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,35 @@ impl FileBuf {
3535
pub fn as_image(&'_ self) -> Image<'_> {
3636
Image { raw: &self.raw }
3737
}
38+
39+
#[must_use]
40+
pub fn into_vec(self) -> alloc::vec::Vec<u8> {
41+
self.raw.into_vec()
42+
}
43+
}
44+
45+
#[cfg(feature = "alloc")]
46+
impl From<FileBuf> for Box<[u8]> {
47+
fn from(value: FileBuf) -> Self {
48+
value.raw
49+
}
50+
}
51+
52+
#[cfg(feature = "alloc")]
53+
impl From<FileBuf> for alloc::vec::Vec<u8> {
54+
fn from(value: FileBuf) -> Self {
55+
value.into_vec()
56+
}
57+
}
58+
59+
#[cfg(feature = "alloc")]
60+
impl TryFrom<FileBuf> for alloc::string::String {
61+
type Error = alloc::string::FromUtf8Error;
62+
63+
fn try_from(value: FileBuf) -> Result<Self, Self::Error> {
64+
let v = value.into_vec();
65+
alloc::string::String::from_utf8(v)
66+
}
3867
}
3968

4069
/// A file loaded from ROM or data dir into the memory.

0 commit comments

Comments
 (0)