diff --git a/ffi/README.md b/ffi/README.md index 58be97b86..90f00bfd8 100644 --- a/ffi/README.md +++ b/ffi/README.md @@ -86,7 +86,7 @@ export's, and adds nothing; another crate's type is refused. | `Option` | a null handle or buffer, or `_option_` | | a `pub const` | a `#define` if a `bool` or integer, else a function returning it | | `impl Into`, `impl AsRef`, or a bound implying one, as a supertrait does | `X`, or `&X` and then `String` or `Vec` where `X` is `str` or `[T]` | -| `impl Into`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl> From for Timed` takes `Bytes`, and any other source as it is, so `impl<'a, V> From<&'a V> for Timed<&'a V>` takes `&V` | +| `impl Into`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl> From for Timed` takes `Bytes`, and by each `Into` whose `Y` does not map, what converts into `Y` in turn, each `Y` once and refusing a chain longer than the crate's recursion limit; any other source as it is, so `impl<'a, V> From<&'a V> for Timed<&'a V>` takes `&V`. Two sources C passes as one buffer, such as `String` and `Vec`, are refused, unless they are forms of one value, as `&str` and `String` are | | `impl IntoIterator`, where `X` is no type parameter | `Vec` | | another type parameter | `serde_json::Value` for a serde `Serialize` or `Deserialize` bound, else the first of `String`, `Bytes`, and `Vec` meeting its bounds, or a foreign implementation of its one exported trait; else an instance of the function at each type the exports implement a trait bounding it for, as `&X` where that meets its bounds too and no bound, its own or one a supertrait implies, makes it outlive the call, so C keeps its handle, and, as an argument of a generic type, at each argument of an instance that meets its bounds and makes each generic type the signature names an instance | diff --git a/ffi/fixtures/api/examples/transcript.rs b/ffi/fixtures/api/examples/transcript.rs index 89c8cdd50..0c4565a69 100644 --- a/ffi/fixtures/api/examples/transcript.rs +++ b/ffi/fixtures/api/examples/transcript.rs @@ -9,8 +9,8 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::task::{Context, Poll, Wake, Waker}; use api_lib::{ - Channel, Counter, Event, LIMIT, Log, Logger, Message, Name, Node, Pair, Point, Registry, Shape, Size, Stack, Stamp, - Tally, Window, + Channel, Counter, Event, LIMIT, Label, Log, Logger, Message, Name, Node, Pair, Point, Registry, Shape, Size, Stack, + Stamp, Tally, Window, }; use bytes::Bytes; @@ -209,6 +209,27 @@ fn main() { println!("len {}", api_lib::len(b"abc")); println!("hex {}", api_lib::hex(Bytes::from_static(b"\xff\x00a"))); println!("timed hex {}", api_lib::timed_hex(Bytes::from_static(b"\xff\x00a"))); + println!("sample hex {}", api_lib::sample_hex(&b"\xff\x00a"[..])); + println!("queued hex {}", api_lib::queued_hex(b"\xff\x00a".to_vec())); + let tick = Label { + name: "tick".to_string(), + at: None, + ttl: None, + }; + println!("tick {}", api_lib::tick_name(tick)); + let rooted = Label { + name: "rooted".to_string(), + at: None, + ttl: None, + }; + println!("rooted {}", api_lib::rooted_name(rooted)); + println!("stored {}", api_lib::stored_text("stored")); + let layer = Label { + name: "layer".to_string(), + at: None, + ttl: None, + }; + println!("layer {}", api_lib::layer_name(layer)); for event in [Event::Moved(p), Event::Named { name: "n".to_string() }, Event::Done] { println!("{}", api_lib::describe(&event)); } diff --git a/ffi/fixtures/api/ffi.toml b/ffi/fixtures/api/ffi.toml index c763b1e16..3fb66cc53 100644 --- a/ffi/fixtures/api/ffi.toml +++ b/ffi/fixtures/api/ffi.toml @@ -2,22 +2,32 @@ package = "api-fixture" prefix = "api" # The list's tail is not `Clone`, so its getter has no copy to return, one instance leaves # out a method the others keep, `Seed` is generic, so no callback implements it, `Payload` -# and `Kept` consume themselves, which no callback can, `Timed` has no instance that -# exports, and +# and `Kept` consume themselves, which no callback can, `Timed`, `Sample`, `Queued`, +# `Tick`, `Tock`, `Scoped`, `Rooted`, `Copied`, `Stored`, and `Layer` only convert, so +# their parameters take what converts into them, and # `field@` leaves out a field alone where a method takes its path, as `Retry`'s and # `Slot`'s do. `Slot` has no such method, so its path alone names its field. A # function instance is left out by its path, as `depth_past` at `polar::Point` is. exclude = [ + "Copied", "Kept", + "Layer", "Node::next", "Pair::swap", "Payload", + "Queued", + "Rooted", + "Sample", + "Scoped", "Seed", "Slot::value", "field@Retry::delay", "field@Slot::value", "Stack::depth_past", + "Stored", + "Tick", "Timed", + "Tock", ] # The field `Retry::limit`, whose name its method takes, and one instance each of `Pair` diff --git a/ffi/fixtures/api/src/lib.rs b/ffi/fixtures/api/src/lib.rs index ab232c1a5..c70806609 100644 --- a/ffi/fixtures/api/src/lib.rs +++ b/ffi/fixtures/api/src/lib.rs @@ -820,6 +820,131 @@ pub fn timed_text<'a, T: serde::Serialize + 'a>(value: impl Into>) serde_json::to_string(value.into().value).expect("a JSON document serializes") } +/// A timed payload on a track, which what converts into one converts into. +pub struct Sample(Timed); + +impl>> From for Sample { + fn from(value: T) -> Self { + Self(value.into()) + } +} + +/// A sample's bytes in hex, which need not be UTF-8, two conversions from what C lends. +pub fn sample_hex(sample: impl Into) -> String { + hex(sample.into().0.value) +} + +/// A sample queued past the conversion, so what converts into it is owned. +pub struct Queued(Sample); + +impl + 'static> From for Queued { + fn from(value: T) -> Self { + Self(value.into()) + } +} + +/// A queued sample's bytes in hex, which need not be UTF-8, three conversions from owned bytes. +pub fn queued_hex(queued: impl Into) -> String { + hex(queued.into().0.0.value) +} + +/// A name from a label, or from what converts into a `Tock`, which converts from what +/// converts into a `Tick`: a cycle, which only the label leaves. +pub struct Tick(String); + +impl From