Skip to content

Commit 32f6572

Browse files
author
nchiasson
committed
Support no_std
1 parent b8151fa commit 32f6572

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ path = "src/lib.rs"
1919
[[bin]]
2020
name = "fcidr"
2121
path = "src/main.rs"
22+
required-features = ["std"]
2223

2324
[badges]
2425
github = { repository = "nicholaschiasson/fcidr" }
@@ -32,3 +33,8 @@ serde = { version = "1.0", optional = true }
3233
serde_json = "1.0"
3334
assert_cmd = "2.0"
3435
predicates = "3.0"
36+
37+
[features]
38+
default = []
39+
std = []
40+
serde = ["dep:serde"]

src/cidr.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::{
1+
extern crate alloc;
2+
3+
use alloc::{format, string::ToString};
4+
use core::{
25
fmt::{Debug, Display},
36
net::Ipv4Addr,
47
str::FromStr,
@@ -135,7 +138,7 @@ impl Default for Cidr {
135138
}
136139

137140
impl Display for Cidr {
138-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
141+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
139142
write!(f, "{}/{}", self.network, self.prefix)
140143
}
141144
}

src/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{error, fmt};
1+
use alloc::string::String;
2+
use core::{error, fmt::Display};
23

34
#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
45
pub enum Error {
@@ -7,8 +8,8 @@ pub enum Error {
78
Parse(String),
89
}
910

10-
impl fmt::Display for Error {
11-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
11+
impl Display for Error {
12+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1213
write!(f, "{self:?}")
1314
}
1415
}

src/fcidr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use std::{cell::RefCell, rc::Rc};
1+
use alloc::{borrow::ToOwned, rc::Rc, vec::Vec};
2+
use core::cell::RefCell;
23

34
use crate::Cidr;
45

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern crate alloc;
2+
13
mod cidr;
24
mod error;
35
mod fcidr;

src/serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(feature = "serde")]
22
#![cfg_attr(doc_cfg, doc(cfg(feature = "serde")))]
33

4-
use std::str::FromStr;
4+
use core::str::FromStr;
55

66
use serde::{de::Visitor, ser::SerializeSeq, Deserialize, Serialize};
77

0 commit comments

Comments
 (0)