Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ffi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export's, and adds nothing; another crate's type is refused.
| `Option<T>` | a null handle or buffer, or `<prefix>_option_<T>` |
| a `pub const` | a `#define` if a `bool` or integer, else a function returning it |
| `impl Into<X>`, `impl AsRef<X>`, or a bound implying one, as a supertrait does | `X`, or `&X` and then `String` or `Vec<T>` where `X` is `str` or `[T]` |
| `impl Into<X>`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl<B: Into<Bytes>> From<B> for Timed<Bytes>` takes `Bytes`, and any other source as it is, so `impl<'a, V> From<&'a V> for Timed<&'a V>` takes `&V` |
| `impl Into<X>`, where `X` does not map | what a `From` implementation into `X` takes: a source parameter by its bounds as above, so `impl<B: Into<Bytes>> From<B> for Timed<Bytes>` takes `Bytes`, and by each `Into<Y>` 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<u8>`, are refused, unless they are forms of one value, as `&str` and `String` are |
| `impl IntoIterator<Item = X>`, where `X` is no type parameter | `Vec<X>` |
| another type parameter | `serde_json::Value` for a serde `Serialize` or `Deserialize` bound, else the first of `String`, `Bytes`, and `Vec<u8>` 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 |

Expand Down
25 changes: 23 additions & 2 deletions ffi/fixtures/api/examples/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
14 changes: 12 additions & 2 deletions ffi/fixtures/api/ffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>`'s do. `Slot<u32>` 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<u8, dep_fixture::Size>::swap",
"Payload",
"Queued",
"Rooted",
"Sample",
"Scoped",
"Seed",
"Slot<u32>::value",
"field@Retry::delay",
"field@Slot<u8>::value",
"Stack::depth_past<api_fixture::polar::Point>",
"Stored",
"Tick",
"Timed",
"Tock",
]

# The field `Retry::limit`, whose name its method takes, and one instance each of `Pair`
Expand Down
125 changes: 125 additions & 0 deletions ffi/fixtures/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,131 @@ pub fn timed_text<'a, T: serde::Serialize + 'a>(value: impl Into<Timed<&'a T>>)
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<Bytes>);

impl<T: Into<Timed<Bytes>>> From<T> 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<Sample>) -> String {
hex(sample.into().0.value)
}

/// A sample queued past the conversion, so what converts into it is owned.
pub struct Queued(Sample);

impl<T: Into<Sample> + 'static> From<T> 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<Queued>) -> 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<Label> for Tick {
fn from(label: Label) -> Self {
Self(label.name)
}
}

impl<T: Into<Tock> + Copy> From<T> for Tick {
fn from(value: T) -> Self {
Self(value.into().0)
}
}

/// What converts into a `Tick` converts into a `Tock`.
pub struct Tock(String);

impl<T: Into<Tick> + Copy> From<T> for Tock {
fn from(value: T) -> Self {
Self(value.into().0)
}
}

/// The name a `Tick` takes.
pub fn tick_name(tick: impl Into<Tick>) -> String {
tick.into().0
}

/// A label's name, scoped to a lifetime it borrows nothing for.
pub struct Scoped<'a>(String, std::marker::PhantomData<&'a ()>);

impl From<Label> for Scoped<'_> {
fn from(label: Label) -> Self {
Self(label.name, std::marker::PhantomData)
}
}

/// What converts into a `Scoped<'static>`, which an owned label does.
pub struct Rooted(Scoped<'static>);

impl<T: Into<Scoped<'static>>> From<T> for Rooted {
fn from(value: T) -> Self {
Self(value.into())
}
}

/// The name a `Rooted` takes, through a target whose lifetime is `'static`.
pub fn rooted_name(rooted: impl Into<Rooted>) -> String {
rooted.into().0.0
}

/// Text copied from a borrow, so `'static` whatever it borrowed.
pub struct Copied<'a>(String, std::marker::PhantomData<&'a ()>);

impl<'a> From<&'a str> for Copied<'static> {
fn from(text: &'a str) -> Self {
Self(text.to_string(), std::marker::PhantomData)
}
}

/// What converts into a `Copied<'static>`, which a borrow C lends does.
pub struct Stored(Copied<'static>);

impl<T: Into<Copied<'static>>> From<T> for Stored {
fn from(value: T) -> Self {
Self(value.into())
}
}

/// The text a `Stored` takes, through a target whose lifetime its source does not borrow for.
pub fn stored_text(stored: impl Into<Stored>) -> String {
stored.into().0.0
}

/// A label's name, layered over a `Vec` of its first type once more for each conversion,
/// until its second type is no longer `u8`.
pub struct Layer<T, U>(String, std::marker::PhantomData<(T, U)>);

impl From<Label> for Layer<u8, u8> {
fn from(label: Label) -> Self {
Self(label.name, std::marker::PhantomData)
}
}

impl<T, S: Into<Layer<Vec<T>, T>> + Copy> From<S> for Layer<T, u8> {
fn from(value: S) -> Self {
Self(value.into().0, std::marker::PhantomData)
}
}

/// The name a `Layer<u8, u8>` takes, through a chain that grows twice and ends.
pub fn layer_name(layer: impl Into<Layer<u8, u8>>) -> String {
layer.into().0
}

pub fn greet(name: impl Into<String>, shape: Shape) -> String {
format!("hello {}, a {shape:?}", name.into())
}
Expand Down
51 changes: 30 additions & 21 deletions ffi/fixtures/reject/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,43 @@ fixtures/reject/src/lib.rs:347:1: rust2-ffi: cannot export fn `stash`: generic p
fixtures/reject/src/lib.rs:362:1: rust2-ffi: cannot export fn `hold`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:367:1: rust2-ffi: cannot export fn `bound`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:372:1: rust2-ffi: cannot export fn `kept`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:377:1: rust2-ffi: cannot export fn `alphabet`: Range `char`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:382:1: rust2-ffi: cannot export fn `naturals`: foreign type `std::ops::RangeFrom`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:387:1: rust2-ffi: cannot export fn `opaques`: borrowed return that is not Clone `Opaque`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:392:1: rust2-ffi: cannot export fn `tried`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:397:1: rust2-ffi: cannot export fn `eventually`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:402:1: rust2-ffi: cannot export trait `Source`: callback signature `items`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:407:1: rust2-ffi: cannot export fn `ones`: foreign type `std::iter::Repeat`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:386:1: rust2-ffi: cannot export fn `holder`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:400:1: rust2-ffi: cannot export fn `lender`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:40:1: rust2-ffi: cannot export fn `peek`: reference to a handle inside a value `std::boxed::Box<Opaque>`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:412:1: rust2-ffi: cannot export fn `words`: foreign type `std::str::Split`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:429:1: rust2-ffi: cannot export fn `launched`: foreign type `std::iter::Chain`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:446:1: rust2-ffi: cannot export fn `launches`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:415:1: rust2-ffi: cannot export fn `outlived`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:430:1: rust2-ffi: cannot export fn `paired`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:453:1: rust2-ffi: cannot export fn `pinner`: generic parameter `std::convert::Into`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:45:1: rust2-ffi: cannot export static `COUNT`: static; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:469:1: rust2-ffi: cannot export fn `pumped`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:474:1: rust2-ffi: cannot export struct `Token`: object no export returns; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:483:1: rust2-ffi: cannot export fn `skipped`: foreign type `std::iter::Skip`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:488:1: rust2-ffi: cannot export fn `merged`: foreign type `std::iter::Copied`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:495:1: rust2-ffi: cannot export fn `values`: foreign type `std::collections::btree_map::IntoValues`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:468:1: rust2-ffi: cannot export fn `grows`: growing conversion `Grows<u8>`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:460:1: note: applies past the recursion limit
fixtures/reject/src/lib.rs:498:1: rust2-ffi: cannot export fn `call`: ambiguous conversion `std::vec::Vec<u8>`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:475:1: note: `std::string::String` converts too, which C passes alike
fixtures/reject/src/lib.rs:49:1: rust2-ffi: cannot export macro `noop`: macro; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:500:1: rust2-ffi: cannot export fn `zeros`: foreign type `std::iter::RepeatN`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:505:1: rust2-ffi: cannot export fn `successes`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:525:1: rust2-ffi: cannot export fn `allocated`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:532:1: rust2-ffi: cannot export fn `flattened`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:556:1: rust2-ffi: cannot export fn `lent`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:574:1: rust2-ffi: cannot export fn `halves`: foreign type `std::str::Split`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:503:1: rust2-ffi: cannot export fn `alphabet`: Range `char`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:508:1: rust2-ffi: cannot export fn `naturals`: foreign type `std::ops::RangeFrom`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:513:1: rust2-ffi: cannot export fn `opaques`: borrowed return that is not Clone `Opaque`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:518:1: rust2-ffi: cannot export fn `tried`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:523:1: rust2-ffi: cannot export fn `eventually`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:528:1: rust2-ffi: cannot export trait `Source`: callback signature `items`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:533:1: rust2-ffi: cannot export fn `ones`: foreign type `std::iter::Repeat`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:538:1: rust2-ffi: cannot export fn `words`: foreign type `std::str::Split`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:555:1: rust2-ffi: cannot export fn `launched`: foreign type `std::iter::Chain`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:572:1: rust2-ffi: cannot export fn `launches`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:57:1: rust2-ffi: cannot export fn `excluded`: excluded type `Excluded`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:595:1: rust2-ffi: cannot export fn `pumped`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:600:1: rust2-ffi: cannot export struct `Token`: object no export returns; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:609:1: rust2-ffi: cannot export fn `skipped`: foreign type `std::iter::Skip`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:614:1: rust2-ffi: cannot export fn `merged`: foreign type `std::iter::Copied`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:621:1: rust2-ffi: cannot export fn `values`: foreign type `std::collections::btree_map::IntoValues`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:626:1: rust2-ffi: cannot export fn `zeros`: foreign type `std::iter::RepeatN`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:631:1: rust2-ffi: cannot export fn `successes`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:651:1: rust2-ffi: cannot export fn `allocated`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:658:1: rust2-ffi: cannot export fn `flattened`: foreign type `std::iter::Flatten`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:682:1: rust2-ffi: cannot export fn `lent`: foreign type `std::vec::IntoIter`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:68:2: rust2-ffi: fn `reject_fixture::audio::encoder_finish` and fn `reject_fixture::audio_encoder::finish` are both `reject_audio_encoder_finish` in C
fixtures/reject/src/lib.rs:63:2: note: fn `reject_fixture::audio_encoder::finish` is here
fixtures/reject/src/lib.rs:6:1: rust2-ffi: cannot export struct `Wrap`: generic type; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:700:1: rust2-ffi: cannot export fn `halves`: foreign type `std::str::Split`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:72:1: rust2-ffi: cannot export fn `letters`: Range `char`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:81:2: rust2-ffi: cannot export method `Text::new`: 'static borrow `&'a str`; exclude it in the config to leave it out
fixtures/reject/src/lib.rs:79:6: note: `'a` is `'static`, as a handle outlives every call
Expand Down
2 changes: 1 addition & 1 deletion ffi/fixtures/reject/ffi.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package = "reject-fixture"
prefix = "reject"
# An exclusion leaves an item or an instance out, so nothing refuses it.
exclude = ["Cell<u16>", "Excluded", "Held"]
exclude = ["Called", "Caller", "Cell<u16>", "Excluded", "Grows", "Held", "Holder", "Lender", "Outlived", "Paired", "Pinned", "Pinner"]

# A field that is none: `min` names nothing of `Limit`. An instance the config leaves out.
[rename]
Expand Down
Loading