From 1c5349106582e836b889b9606be1a8c190cd0640 Mon Sep 17 00:00:00 2001 From: Pedro Nobre Date: Sat, 4 Jul 2026 06:35:59 +0100 Subject: [PATCH 1/2] splice and eco_format now work on no_std. added a missing test for eco_format. --- Cargo.toml | 2 +- src/string.rs | 4 ++-- src/vendor/vec/splice.rs | 3 +++ tests/tests.rs | 10 +++++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a3ff6f6..34615da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ categories = ["data-structures", "no-std"] keywords = ["string", "vector", "sso", "cow"] [features] -default = ["std"] +default = [] std = [] [dependencies] diff --git a/src/string.rs b/src/string.rs index 756cb83..bbf7f3e 100644 --- a/src/string.rs +++ b/src/string.rs @@ -26,9 +26,9 @@ use crate::dynamic::{DynamicVec, InlineVec}; #[clippy::format_args] macro_rules! eco_format { ($($tts:tt)*) => {{ - use ::std::fmt::Write; + use ::core::fmt::Write; let mut s = $crate::EcoString::new(); - ::std::write!(s, $($tts)*).unwrap(); + ::core::write!(s, $($tts)*).unwrap(); s }}; } diff --git a/src/vendor/vec/splice.rs b/src/vendor/vec/splice.rs index 884f89a..29ce8bf 100644 --- a/src/vendor/vec/splice.rs +++ b/src/vendor/vec/splice.rs @@ -5,6 +5,9 @@ use core::ptr; use core::slice; +#[cfg(not(feature = "std"))] +use alloc::vec::Vec; + use crate::EcoVec; use super::Drain; diff --git a/tests/tests.rs b/tests/tests.rs index 79aa890..8ec6d01 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -10,7 +10,7 @@ use std::mem; use std::sync::atomic::{AtomicUsize, Ordering::*}; use ecow::string::ToEcoString; -use ecow::{eco_vec, EcoString, EcoVec}; +use ecow::{eco_format, eco_vec, EcoString, EcoVec}; const ALPH: &str = "abcdefghijklmnopqrstuvwxyz"; const LIMIT: usize = EcoString::INLINE_LIMIT; @@ -371,6 +371,14 @@ fn test_array_from_vec() { assert_eq!(<[String; 0]>::try_from(EcoVec::new()).unwrap(), <[String; 0]>::default()); } +#[test] +fn test_str_macro() { + assert_eq!( + eco_format!("Hello, {}! The secret number is {}.", "world".to_owned(), 42), + "Hello, world! The secret number is 42." + ); +} + #[test] fn test_str_new() { // Test inline strings. From 130e6eb08607c3ed4d13aed9a8379ebe61d8a457 Mon Sep 17 00:00:00 2001 From: Pedro Nobre Date: Sat, 4 Jul 2026 06:36:50 +0100 Subject: [PATCH 2/2] added std flag back to default. small mistake --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 34615da..a3ff6f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ categories = ["data-structures", "no-std"] keywords = ["string", "vector", "sso", "cow"] [features] -default = [] +default = ["std"] std = [] [dependencies]