diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2ea4e3fb..26a32ebe2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,6 +27,15 @@ jobs: run: rustup show - uses: actions/checkout@v3 + + - name: Check + run: + - cargo check --all-targets + - cargo check --all-targets --all-features + - cargo check --all-targets --no-default-features + - cargo check --all-targets --no-default-features --features serde + - cargo check --all-targets --no-default-features --features dir-entry-path + - name: Build run: cargo build --release --verbose diff --git a/CHANGELOG.md b/CHANGELOG.md index 906afc2cd..a17370346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed macro hygiene for `path!`. - Fixed build error that would occur on Windows systems. +- Fixed compilation without default features. - Added path iteration utilities ([#47][]) ## Changed diff --git a/src/fs.rs b/src/fs.rs index 1081e84d9..8fa16d8d1 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -10,7 +10,6 @@ use core::{ }; use generic_array::typenum::marker_traits::Unsigned; use littlefs2_sys as ll; -use serde::{Deserialize, Serialize}; // so far, don't need `heapless-bytes`. pub type Bytes = generic_array::GenericArray; @@ -18,7 +17,6 @@ pub type Bytes = generic_array::GenericArray; use crate::{ driver, io::{self, Error, OpenSeekFrom, Result}, - path, path::{Path, PathBuf}, }; @@ -161,7 +159,8 @@ pub struct Filesystem<'a, Storage: driver::Storage> { } /// Regular file vs directory -#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum FileType { File, Dir, @@ -180,7 +179,8 @@ impl FileType { } /// File type (regular vs directory) and size of a file. -#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Debug, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct Metadata { file_type: FileType, size: usize, @@ -225,6 +225,7 @@ impl From for Metadata { } } +#[cfg(feature = "dir-entry-path")] struct RemoveDirAllProgress { files_removed: usize, skipped_any: bool, @@ -320,6 +321,7 @@ impl Filesystem<'_, Storage> { } /// Returns number of deleted files + whether the directory was fully deleted or not + #[cfg(feature = "dir-entry-path")] fn remove_dir_all_where_inner

( &self, path: &Path, @@ -328,6 +330,8 @@ impl Filesystem<'_, Storage> { where P: Fn(&DirEntry) -> bool, { + use crate::path; + if !path.exists(self) { debug_now!("no such directory {}, early return", path); return Ok(RemoveDirAllProgress { @@ -993,7 +997,8 @@ impl io::Write for File<'_, '_, S> { } } -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DirEntry { file_name: PathBuf, metadata: Metadata, diff --git a/src/path.rs b/src/path.rs index 8cf1e55df..3cfc982ef 100644 --- a/src/path.rs +++ b/src/path.rs @@ -6,7 +6,6 @@ use core::{ ffi::{c_char, CStr}, fmt, iter::FusedIterator, - marker::PhantomData, ops, ptr, slice, str, }; @@ -553,6 +552,7 @@ impl ops::Deref for PathBuf { } } +#[cfg(feature = "serde")] impl serde::Serialize for PathBuf { fn serialize(&self, serializer: S) -> core::result::Result where @@ -562,11 +562,14 @@ impl serde::Serialize for PathBuf { } } +#[cfg(feature = "serde")] impl<'de> serde::Deserialize<'de> for PathBuf { fn deserialize(deserializer: D) -> core::result::Result where D: serde::Deserializer<'de>, { + use core::marker::PhantomData; + struct ValueVisitor<'de>(PhantomData<&'de ()>); impl<'de> serde::de::Visitor<'de> for ValueVisitor<'de> {