Struct littlefs2::fs::File [−][src]
Implementations
impl<'a, 'b, Storage: Storage> File<'a, 'b, Storage>
[src]
pub fn allocate() -> FileAllocation<Storage>
[src]
pub fn with_options() -> OpenOptions
[src]
Returns a new OpenOptions object.
This function returns a new OpenOptions object that you can use to open or create a file with specific options if open() or create() are not appropriate.
It is equivalent to OpenOptions::new() but allows you to write more readable code. This also avoids the need to import OpenOptions`.
pub unsafe fn open(
fs: &'b Filesystem<'a, Storage>,
alloc: &'b mut FileAllocation<Storage>,
path: &Path
) -> Result<Self>
[src]
fs: &'b Filesystem<'a, Storage>,
alloc: &'b mut FileAllocation<Storage>,
path: &Path
) -> Result<Self>
pub fn open_and_then<R>(
fs: &Filesystem<'a, Storage>,
path: &Path,
f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>
) -> Result<R>
[src]
fs: &Filesystem<'a, Storage>,
path: &Path,
f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>
) -> Result<R>
pub unsafe fn create(
fs: &'b Filesystem<'a, Storage>,
alloc: &'b mut FileAllocation<Storage>,
path: &Path
) -> Result<Self>
[src]
fs: &'b Filesystem<'a, Storage>,
alloc: &'b mut FileAllocation<Storage>,
path: &Path
) -> Result<Self>
pub fn create_and_then<R>(
fs: &Filesystem<'a, Storage>,
path: &Path,
f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>
) -> Result<R>
[src]
fs: &Filesystem<'a, Storage>,
path: &Path,
f: impl FnOnce(&File<'_, '_, Storage>) -> Result<R>
) -> Result<R>
pub unsafe fn borrow_filesystem<'c>(&'c mut self) -> &'c Filesystem<'a, Storage>
[src]
pub unsafe fn close(self) -> Result<()>
[src]
Sync the file and drop it from the internal linked list. Not doing this is UB, which is why we have all the closure-based APIs.
TODO: check if this can be closed >1 times, if so make it safe
Update: It seems like there’s an assertion on a flag called LFS_F_OPENED
:
https://github.com/ARMmbed/littlefs/blob/4c9146ea539f72749d6cc3ea076372a81b12cb11/lfs.c#L2549
https://github.com/ARMmbed/littlefs/blob/4c9146ea539f72749d6cc3ea076372a81b12cb11/lfs.c#L2566
- On second call, shouldn’t find ourselves in the “mlist of mdirs”
- Since we don’t have dynamically allocated buffers, at least we don’t hit the double-free.
- Not sure what happens in
lfs_file_sync
, but it should be easy to just error on not LFS_F_OPENED…
pub fn sync(&self) -> Result<()>
[src]
Synchronize file contents to storage.
pub fn len(&self) -> Result<usize>
[src]
Size of the file in bytes.
pub fn set_len(&self, size: usize) -> Result<()>
[src]
Truncates or extends the underlying file, updating the size of this file to become size.
If the size is less than the current file’s size, then the file will be shrunk. If it is greater than the current file’s size, then the file will be extended to size and have all of the intermediate data filled in with 0s.
pub fn read_to_end<N: ArrayLength<u8>>(
&self,
buf: &mut Vec<u8, N>
) -> Result<usize>
[src]
&self,
buf: &mut Vec<u8, N>
) -> Result<usize>
pub fn read(&self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn seek(&self, pos: SeekFrom) -> Result<usize>
[src]
pub fn write(&self, buf: &[u8]) -> Result<usize>
[src]
Trait Implementations
impl<S: Storage> Read for File<'_, '_, S>
[src]
fn read(&self, buf: &mut [u8]) -> Result<usize>
[src]
fn read_exact(&self, buf: &mut [u8]) -> Result<()>
[src]
impl<S: Storage> Seek for File<'_, '_, S>
[src]
impl<S: Storage> Write for File<'_, '_, S>
[src]
Auto Trait Implementations
impl<'a, 'b, S> !RefUnwindSafe for File<'a, 'b, S>
impl<'a, 'b, S> !Send for File<'a, 'b, S>
impl<'a, 'b, S> !Sync for File<'a, 'b, S>
impl<'a, 'b, S> Unpin for File<'a, 'b, S> where
'a: 'b,
'a: 'b,
impl<'a, 'b, S> !UnwindSafe for File<'a, 'b, S>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,