Skip to content

Commit

Permalink
Merge pull request #7 from siketyan/no-std
Browse files Browse the repository at this point in the history
feat: no_std support
  • Loading branch information
siketyan committed Sep 24, 2022
2 parents 9477be4 + 343a9a4 commit d487c3e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,14 @@ Add to your Cargo.toml as a dependency as follows:
apdu = "0.2"
```

## 馃洜 no_std support
apdu-core crate does support no_std environments.
If you are using this crate in no_std, turn `std` feature off by disabling default features:

```toml
[dependencies]
apdu-core = { version = "0.2", default-features = false }
```

## 馃搫 Documentation
See [docs.rs](https://docs.rs/apdu/).
4 changes: 4 additions & 0 deletions apdu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ authors = [
]

[dependencies]

[features]
std = []
default = ["std"]
3 changes: 3 additions & 0 deletions apdu-core/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use alloc::vec;
use alloc::vec::Vec;

/// An APDU command to be transmitted
pub struct Command {
pub cla: u8,
Expand Down
5 changes: 3 additions & 2 deletions apdu-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{Display, Formatter};
use core::fmt::{Display, Formatter};

use crate::Response;

Expand All @@ -9,7 +9,7 @@ pub struct Error {
}

impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
let (sw1, sw2) = self.response.trailer;

write!(
Expand All @@ -20,4 +20,5 @@ impl Display for Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
4 changes: 4 additions & 0 deletions apdu-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Core library for composing APDU commands and parsing their responses.

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

mod command;
mod error;
mod response;
Expand Down

0 comments on commit d487c3e

Please sign in to comment.