diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2ea4e3fb..4f64581b0 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 d074c7244..e046f5fb8 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 ca4da59d3..a83054045 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -9,7 +9,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; @@ -17,7 +16,6 @@ pub type Bytes = generic_array::GenericArray; use crate::{ driver, io::{self, Error, OpenSeekFrom, Result}, - path, path::{Path, PathBuf}, }; @@ -160,7 +158,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, @@ -179,7 +178,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, @@ -224,6 +224,7 @@ impl From for Metadata { } } +#[cfg(feature = "dir-entry-path")] struct RemoveDirAllProgress { files_removed: usize, skipped_any: bool, @@ -319,6 +320,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, @@ -327,6 +329,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 { @@ -992,7 +996,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 719d42e33..20fe3379a 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,9 +1,6 @@ //! Paths -use core::{ - cmp::Ordering, convert::TryFrom, fmt, iter::FusedIterator, marker::PhantomData, ops, ptr, - slice, str, -}; +use core::{cmp::Ordering, convert::TryFrom, fmt, iter::FusedIterator, ops, ptr, slice, str}; use cstr_core::CStr; use cty::{c_char, size_t}; @@ -551,6 +548,7 @@ impl ops::Deref for PathBuf { } } +#[cfg(feature = "serde")] impl serde::Serialize for PathBuf { fn serialize(&self, serializer: S) -> core::result::Result where @@ -560,11 +558,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> { diff --git a/src/tests.rs b/src/tests.rs index 14a450a6e..7e7498d23 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -395,6 +395,7 @@ fn test_fancy_open() { } #[test] +#[cfg(feature = "dir-entry-path")] fn remove_dir_all_where() { let mut backend = Ram::default(); let mut storage = RamStorage::new(&mut backend);