aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-22 12:05:11 -0700
committeriximeow <me@iximeow.net>2024-06-22 12:05:11 -0700
commit0c69ee37f98ce616df5237cbe74952c2a28cc5cb (patch)
tree03054f2df3ead67cc6ce39e9d43d2ddc09a92ab8
parent872adb302b1c51cda7b1e99e128129e230e24ff8 (diff)
VecSink only needs `alloc`, hide struct items
-rw-r--r--CHANGELOG16
-rw-r--r--src/annotation/mod.rs36
2 files changed, 36 insertions, 16 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3bc66ce..502b165 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,11 @@ TODO: impls of `fn one` and `fn zero` so downstream users don't have to import n
## 0.3.0
+added a new crate feature flag, `alloc`.
+ this flag is for any features that do not require std, but do require
+ containers from `liballoc`. good examples are `alloc::string::String` or
+ `alloc::vec::Vec`.
+
added `yaxpeax_arch::display::DisplaySink` after revisiting output colorization.
`DisplaySink` is better suited for general markup, rather than being focused
specifically on ANSI/console text coloring. `YaxColors` also simply does not
@@ -20,9 +25,9 @@ added `yaxpeax_arch::display::DisplaySink` after revisiting output colorization.
needs to be styled is only written to after intermediate buffering.
`DisplaySink` also includes specializable functions for writing text to an
-output, and the implementation for `alloc::string::String` takes advantage of
-this: writing through `impl DisplaySink for String` will often be substantially
-more performant than writing through `fmt::Write`.
+ output, and the implementation for `alloc::string::String` takes advantage of
+ this: writing through `impl DisplaySink for String` will often be substantially
+ more performant than writing through `fmt::Write`.
added `yaxpeax_arch::safer_unchecked` to aid in testing use of unchecked methods
these were originally added to improve yaxpeax-x86 testing:
@@ -30,6 +35,11 @@ added `yaxpeax_arch::safer_unchecked` to aid in testing use of unchecked methods
yaxpeax-arch as they're generally applicable and overall wonderful tools.
thank you again 522!
+made VecSink's `records` private. instead of extracting records from the struct
+ by accessing this field directly, call `VecSink::into_inner()`.
+
+made VecSink is now available through the `alloc` feature flag as well as `std`.
+
## 0.2.8
added an impl of `From<ReadError>` for `StandardPartialDecoderError`, matching the existing `StandardDecodeError` impl.
diff --git a/src/annotation/mod.rs b/src/annotation/mod.rs
index 0d1f1f8..9edf262 100644
--- a/src/annotation/mod.rs
+++ b/src/annotation/mod.rs
@@ -94,24 +94,34 @@ impl<T> DescriptionSink<T> for NullSink {
fn record(&mut self, _start: u32, _end: u32, _description: T) { }
}
-#[cfg(feature = "std")]
-pub struct VecSink<T: Clone + Display> {
- pub records: std::vec::Vec<(u32, u32, T)>
-}
+#[cfg(feature = "alloc")]
+mod vec_sink {
+ use alloc::vec::Vec;
+ use core::fmt::Display;
+ use crate::annotation::DescriptionSink;
-#[cfg(feature = "std")]
-impl<T: Clone + Display> VecSink<T> {
- pub fn new() -> Self {
- VecSink { records: std::vec::Vec::new() }
+ pub struct VecSink<T: Clone + Display> {
+ pub records: Vec<(u32, u32, T)>
+ }
+
+ impl<T: Clone + Display> VecSink<T> {
+ pub fn new() -> Self {
+ VecSink { records: Vec::new() }
+ }
+
+ pub fn into_inner(self) -> Vec<(u32, u32, T)> {
+ self.records
+ }
}
-}
-#[cfg(feature = "std")]
-impl<T: Clone + Display> DescriptionSink<T> for VecSink<T> {
- fn record(&mut self, start: u32, end: u32, description: T) {
- self.records.push((start, end, description));
+ impl<T: Clone + Display> DescriptionSink<T> for VecSink<T> {
+ fn record(&mut self, start: u32, end: u32, description: T) {
+ self.records.push((start, end, description));
+ }
}
}
+#[cfg(feature = "alloc")]
+pub use vec_sink::VecSink;
pub trait FieldDescription {
fn id(&self) -> u32;