diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-12-21 04:20:53 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-12-22 08:05:20 +0000 |
| commit | 96708614ba46c42f87b23f2a957c510499d8811e (patch) | |
| tree | 372dcf90f1a6fdf1b90f5d006ce7a32717f47166 /subprojects/thiserror/tests/no-std | |
| parent | 0ec856797256b5d9807929e1b32c03756eb43124 (diff) | |
| download | gentoo-utils-master.tar.gz | |
port to meson cargoHEADmasterfeature/port-to-meson-cargo
Use the new unstable meson cargo support. This simplifies the
meson.build script and allows to use crates such as clap that require
picking up features from Cargo.toml.
This also allows us to not embed thiserror in subprojects, and instead
use a wrap file with a custom meson.build and some patches to make it
compile without running its build.rs script.
Diffstat (limited to 'subprojects/thiserror/tests/no-std')
| -rw-r--r-- | subprojects/thiserror/tests/no-std/Cargo.toml | 12 | ||||
| -rw-r--r-- | subprojects/thiserror/tests/no-std/test.rs | 58 |
2 files changed, 0 insertions, 70 deletions
diff --git a/subprojects/thiserror/tests/no-std/Cargo.toml b/subprojects/thiserror/tests/no-std/Cargo.toml deleted file mode 100644 index 8b03d2f..0000000 --- a/subprojects/thiserror/tests/no-std/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "thiserror_no_std_test" -version = "0.0.0" -authors = ["David Tolnay <dtolnay@gmail.com>"] -edition = "2021" -publish = false - -[lib] -path = "test.rs" - -[dependencies] -thiserror = { path = "../..", default-features = false } diff --git a/subprojects/thiserror/tests/no-std/test.rs b/subprojects/thiserror/tests/no-std/test.rs deleted file mode 100644 index da7899c..0000000 --- a/subprojects/thiserror/tests/no-std/test.rs +++ /dev/null @@ -1,58 +0,0 @@ -#![no_std] - -use thiserror::Error; - -#[derive(Error, Debug)] -pub enum Error { - #[error("Error::E")] - E(#[from] SourceError), -} - -#[derive(Error, Debug)] -#[error("SourceError {field}")] -pub struct SourceError { - pub field: i32, -} - -#[cfg(test)] -mod tests { - use crate::{Error, SourceError}; - use core::error::Error as _; - use core::fmt::{self, Write}; - use core::mem; - - struct Buf<'a>(&'a mut [u8]); - - impl Write for Buf<'_> { - fn write_str(&mut self, s: &str) -> fmt::Result { - if s.len() <= self.0.len() { - let (out, rest) = mem::take(&mut self.0).split_at_mut(s.len()); - out.copy_from_slice(s.as_bytes()); - self.0 = rest; - Ok(()) - } else { - Err(fmt::Error) - } - } - } - - #[test] - fn test() { - let source = SourceError { field: -1 }; - let error = Error::from(source); - - let source = error - .source() - .unwrap() - .downcast_ref::<SourceError>() - .unwrap(); - - let mut msg = [b'~'; 17]; - write!(Buf(&mut msg), "{error}").unwrap(); - assert_eq!(msg, *b"Error::E~~~~~~~~~"); - - let mut msg = [b'~'; 17]; - write!(Buf(&mut msg), "{source}").unwrap(); - assert_eq!(msg, *b"SourceError -1~~~"); - } -} |
