Skip to content

Commit

Permalink
feat: add support for no_std env
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Sep 12, 2024
1 parent 4b490d6 commit c88ef94
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 32 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
version = "22.0.0"
edition = "2021"
rust-version = "1.74.0"
rust-version = "1.81.0"

[[bin]]
name = "stellar-xdr"
Expand All @@ -30,17 +30,15 @@ clap = { version = "4.2.4", default-features = false, features = ["std", "derive
serde_json = { version = "1.0.89", optional = true }
thiserror = { version = "1.0.37", optional = true }
schemars = { version = "0.8.16", optional = true }
embedded-io = { version = "0.6.1", default-features = false, optional = true }
embedded-io-cursor = { git = "https://github.com/lightsail-network/embedded-io-cursor", rev = "0b7ff9270d7ec1d3204375650f04cb0258ac1ada", default-features = false, features = ["alloc"], optional = true }
# TODO: embedded-io-cursor not published yet.
embedded-io-extras = { version = "0.0.1", default-features = false, features = ["alloc"], optional = true }

[dev-dependencies]
serde_json = "1.0.89"

[features]
default = ["std", "curr"]
std = ["alloc"]
alloc = ["dep:hex", "dep:stellar-strkey", "dep:embedded-io", "dep:embedded-io-cursor", "escape-bytes/alloc", "hex/alloc"]
alloc = ["dep:hex", "dep:stellar-strkey", "dep:embedded-io-extras", "escape-bytes/alloc", "hex/alloc"]
curr = []
next = []

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CARGO_HACK_ARGS=--feature-powerset --exclude-features default --group-features b
CARGO_DOC_ARGS?=--open

# TODO: Update this after https://github.com/stellar/xdrgen/pull/205 is merged
XDRGEN_VERSION=ecf547f1bca98545378e55c7e55aa0ef3cf4e66a
XDRGEN_VERSION=3bac661688af0615a7192271b79ced8cd30e9dd4
# XDRGEN_LOCAL=1
XDRGEN_TYPES_CUSTOM_STR_IMPL_CURR=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12,ClaimableBalanceId
XDRGEN_TYPES_CUSTOM_STR_IMPL_NEXT=PublicKey,AccountId,MuxedAccount,MuxedAccountMed25519,SignerKey,SignerKeyEd25519SignedPayload,NodeId,ScAddress,AssetCode,AssetCode4,AssetCode12,ClaimableBalanceId
Expand Down
22 changes: 11 additions & 11 deletions src/curr/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ use std::{
};

#[cfg(all(not(feature = "std"), feature = "alloc"))]
use embedded_io::{Error as _, ErrorType, Read, Write};
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use embedded_io_cursor::Cursor;
use embedded_io_extras::{Cursor, Error as _, ErrorType, Read, Write};

/// Error contains all errors returned by functions in this crate. It can be
/// compared via `PartialEq`, however any contained IO errors will only be
Expand All @@ -129,7 +127,7 @@ pub enum Error {
#[cfg(feature = "std")]
Io(io::Error),
#[cfg(all(not(feature = "std"), feature = "alloc"))]
Io(embedded_io::ErrorKind),
Io(embedded_io_extras::ErrorKind),
DepthLimitExceeded,
#[cfg(feature = "serde_json")]
Json(serde_json::Error),
Expand All @@ -154,21 +152,23 @@ impl PartialEq for Error {
}

#[cfg(all(not(feature = "std"), feature = "alloc"))]
impl embedded_io::Error for Error {
fn kind(&self) -> embedded_io::ErrorKind {
impl embedded_io_extras::Error for Error {
fn kind(&self) -> embedded_io_extras::ErrorKind {
match self {
Self::Io(e) => *e,
_ => embedded_io::ErrorKind::Other,
_ => embedded_io_extras::ErrorKind::Other,
}
}
}

#[cfg(all(not(feature = "std"), feature = "alloc"))]
impl From<embedded_io::ReadExactError<Error>> for Error {
fn from(value: embedded_io::ReadExactError<Error>) -> Self {
impl From<embedded_io_extras::ReadExactError<Error>> for Error {
fn from(value: embedded_io_extras::ReadExactError<Error>) -> Self {
match value {
embedded_io::ReadExactError::UnexpectedEof => Error::Io(embedded_io::ErrorKind::Other),
embedded_io::ReadExactError::Other(e) => e,
embedded_io_extras::ReadExactError::UnexpectedEof => {
Error::Io(embedded_io_extras::ErrorKind::Other)
}
embedded_io_extras::ReadExactError::Other(e) => e,
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/next/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ use std::{
};

#[cfg(all(not(feature = "std"), feature = "alloc"))]
use embedded_io::{Error as _, ErrorType, Read, Write};
#[cfg(all(not(feature = "std"), feature = "alloc"))]
use embedded_io_cursor::Cursor;
use embedded_io_extras::{Cursor, Error as _, ErrorType, Read, Write};

/// Error contains all errors returned by functions in this crate. It can be
/// compared via `PartialEq`, however any contained IO errors will only be
Expand All @@ -129,7 +127,7 @@ pub enum Error {
#[cfg(feature = "std")]
Io(io::Error),
#[cfg(all(not(feature = "std"), feature = "alloc"))]
Io(embedded_io::ErrorKind),
Io(embedded_io_extras::ErrorKind),
DepthLimitExceeded,
#[cfg(feature = "serde_json")]
Json(serde_json::Error),
Expand All @@ -154,21 +152,23 @@ impl PartialEq for Error {
}

#[cfg(all(not(feature = "std"), feature = "alloc"))]
impl embedded_io::Error for Error {
fn kind(&self) -> embedded_io::ErrorKind {
impl embedded_io_extras::Error for Error {
fn kind(&self) -> embedded_io_extras::ErrorKind {
match self {
Self::Io(e) => *e,
_ => embedded_io::ErrorKind::Other,
_ => embedded_io_extras::ErrorKind::Other,
}
}
}

#[cfg(all(not(feature = "std"), feature = "alloc"))]
impl From<embedded_io::ReadExactError<Error>> for Error {
fn from(value: embedded_io::ReadExactError<Error>) -> Self {
impl From<embedded_io_extras::ReadExactError<Error>> for Error {
fn from(value: embedded_io_extras::ReadExactError<Error>) -> Self {
match value {
embedded_io::ReadExactError::UnexpectedEof => Error::Io(embedded_io::ErrorKind::Other),
embedded_io::ReadExactError::Other(e) => e,
embedded_io_extras::ReadExactError::UnexpectedEof => {
Error::Io(embedded_io_extras::ErrorKind::Other)
}
embedded_io_extras::ReadExactError::Other(e) => e,
}
}
}
Expand Down

0 comments on commit c88ef94

Please sign in to comment.