Skip to content

Commit

Permalink
Fix compilation without default features
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-nitrokey committed Jun 2, 2024
1 parent 498fee7 commit be44c0b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ 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<SIZE> = generic_array::GenericArray<u8, SIZE>;

use crate::{
driver,
io::{self, Error, OpenSeekFrom, Result},
path,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -224,6 +224,7 @@ impl From<ll::lfs_info> for Metadata {
}
}

#[cfg(feature = "dir-entry-path")]
struct RemoveDirAllProgress {
files_removed: usize,
skipped_any: bool,
Expand Down Expand Up @@ -319,6 +320,7 @@ impl<Storage: driver::Storage> 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<P>(
&self,
path: &Path,
Expand All @@ -327,6 +329,8 @@ impl<Storage: driver::Storage> 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 {
Expand Down Expand Up @@ -992,7 +996,8 @@ impl<S: driver::Storage> 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,
Expand Down
9 changes: 5 additions & 4 deletions src/path.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -551,6 +548,7 @@ impl ops::Deref for PathBuf {
}
}

#[cfg(feature = "serde")]
impl serde::Serialize for PathBuf {
fn serialize<S>(&self, serializer: S) -> core::result::Result<S::Ok, S::Error>
where
Expand All @@ -560,11 +558,14 @@ impl serde::Serialize for PathBuf {
}
}

#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for PathBuf {
fn deserialize<D>(deserializer: D) -> core::result::Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
use core::marker::PhantomData;

struct ValueVisitor<'de>(PhantomData<&'de ()>);

impl<'de> serde::de::Visitor<'de> for ValueVisitor<'de> {
Expand Down
1 change: 1 addition & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit be44c0b

Please sign in to comment.