Rename Annotation trait to Annotate
This commit is contained in:
parent
5c257b0f74
commit
99aa11e903
@ -67,7 +67,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file does not exist or cannot be read.
|
||||
/// This function may throw if the file does not exist or could not be read.
|
||||
pub async extern "Lua-C" fn read(path: &str) -> Result<Vec<u8>> {
|
||||
Ok(tokio::fs::read(path).await?)
|
||||
}
|
||||
@ -78,7 +78,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file does not exist or cannot be read.
|
||||
/// This function may throw if the file does not exist or could not be read.
|
||||
pub extern "Lua-C" fn read_sync(path: &str) -> Result<Vec<u8>> {
|
||||
Ok(std::fs::read(path)?)
|
||||
}
|
||||
@ -87,7 +87,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file cannot be written.
|
||||
/// This function may throw if the file could not be written.
|
||||
pub async extern "Lua-C" fn write(path: &str, contents: &[u8]) -> Result<()> {
|
||||
Ok(tokio::fs::write(path, contents).await?)
|
||||
}
|
||||
@ -98,7 +98,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file cannot be written.
|
||||
/// This function may throw if the file could not be written.
|
||||
pub extern "Lua-C" fn write_sync(path: &str, contents: &[u8]) -> Result<()> {
|
||||
Ok(std::fs::write(path, contents)?)
|
||||
}
|
||||
@ -107,7 +107,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
pub async extern "Lua-C" fn read_dir(path: &str) -> Result<lb_read_dir> {
|
||||
Ok(lb_read_dir::new(tokio::fs::read_dir(path).await?))
|
||||
}
|
||||
@ -118,7 +118,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
pub extern "Lua-C" fn read_dir_sync(path: &str) -> Result<lb_read_dir_sync> {
|
||||
Ok(lb_read_dir_sync::new(std::fs::read_dir(path)?))
|
||||
}
|
||||
@ -156,7 +156,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the temporary directory cannot be created.
|
||||
/// This function may throw if the temporary directory could not be created.
|
||||
pub extern "Lua-C" fn temp_dir() -> Result<lb_temp_dir> {
|
||||
Ok(lb_temp_dir::new(tempfile::tempdir()?))
|
||||
}
|
||||
@ -165,7 +165,7 @@ impl lb_fslib {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the temporary directory cannot be created.
|
||||
/// This function may throw if the temporary directory could not be created.
|
||||
pub extern "Lua-C" fn temp_dir_in(path: &str) -> Result<lb_temp_dir> {
|
||||
Ok(lb_temp_dir::new(tempfile::tempdir_in(path)?))
|
||||
}
|
||||
@ -186,7 +186,7 @@ impl lb_read_dir {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
#[call]
|
||||
pub async extern "Lua-C" fn next(&self) -> Result<Option<lb_dir_entry>> {
|
||||
Ok(self
|
||||
@ -213,7 +213,7 @@ impl lb_read_dir_sync {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
#[call]
|
||||
pub extern "Lua-C" fn next(&self) -> Result<Option<lb_dir_entry_sync>> {
|
||||
Ok(self
|
||||
@ -250,7 +250,7 @@ impl lb_dir_entry {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file type cannot be determined.
|
||||
/// This function may throw if the file type could not be determined.
|
||||
pub async extern "Lua-C" fn r#type(&self) -> Result<lb_file_type> {
|
||||
Ok(lb_file_type::new(self.0.file_type().await?))
|
||||
}
|
||||
@ -259,7 +259,7 @@ impl lb_dir_entry {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the metadata cannot be retrieved.
|
||||
/// This function may throw if the metadata could not be retrieved.
|
||||
pub async extern "Lua-C" fn metadata(&self) -> Result<lb_file_meta> {
|
||||
Ok(lb_file_meta::new(self.0.metadata().await?))
|
||||
}
|
||||
@ -302,7 +302,7 @@ impl lb_dir_entry_sync {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the file type cannot be determined.
|
||||
/// This function may throw if the file type could not be determined.
|
||||
pub extern "Lua-C" fn r#type(&self) -> Result<lb_file_type> {
|
||||
Ok(lb_file_type::new(self.0.file_type()?))
|
||||
}
|
||||
@ -311,7 +311,7 @@ impl lb_dir_entry_sync {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the metadata cannot be retrieved.
|
||||
/// This function may throw if the metadata could not be retrieved.
|
||||
pub extern "Lua-C" fn metadata(&self) -> Result<lb_file_meta> {
|
||||
Ok(lb_file_meta::new(self.0.metadata()?))
|
||||
}
|
||||
@ -418,7 +418,7 @@ impl lb_file_meta {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the creation time cannot be retrieved.
|
||||
/// This function may throw if the creation time could not be retrieved.
|
||||
pub extern "Lua-C" fn created(&self) -> Result<f64> {
|
||||
Ok(self
|
||||
.0
|
||||
@ -432,7 +432,7 @@ impl lb_file_meta {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the modification time cannot be retrieved.
|
||||
/// This function may throw if the modification time could not be retrieved.
|
||||
pub extern "Lua-C" fn modified(&self) -> Result<f64> {
|
||||
Ok(self
|
||||
.0
|
||||
@ -446,7 +446,7 @@ impl lb_file_meta {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the access time cannot be retrieved.
|
||||
/// This function may throw if the access time could not be retrieved.
|
||||
pub extern "Lua-C" fn accessed(&self) -> Result<f64> {
|
||||
Ok(self
|
||||
.0
|
||||
@ -509,7 +509,7 @@ impl lb_walk_dir {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
#[call]
|
||||
pub extern "Lua-C" fn next(&self) -> Result<Option<lb_walk_dir_entry>> {
|
||||
Ok(self
|
||||
@ -551,7 +551,7 @@ impl lb_walk_dir_entry {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the metadata cannot be retrieved.
|
||||
/// This function may throw if the metadata could not be retrieved.
|
||||
pub extern "Lua-C" fn metadata(&self) -> Result<lb_file_meta> {
|
||||
Ok(lb_file_meta::new(self.0.metadata()?))
|
||||
}
|
||||
@ -606,7 +606,7 @@ impl lb_glob_dir {
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function may throw if the directory cannot be read.
|
||||
/// This function may throw if the directory could not be read.
|
||||
#[call]
|
||||
pub extern "Lua-C" fn next(&self) -> Result<Option<lb_walk_dir_entry>> {
|
||||
while let Some(res) = self.iter.try_borrow_mut()?.next() {
|
||||
|
@ -510,12 +510,12 @@ pub struct lb_socketaddr(#[opaque] SocketAddr);
|
||||
|
||||
#[metatype]
|
||||
impl lb_socketaddr {
|
||||
/// Returns the IP part of this address.
|
||||
/// The IP part of this address.
|
||||
pub extern "Lua-C" fn ip(&self) -> lb_ipaddr {
|
||||
self.0.ip().into()
|
||||
}
|
||||
|
||||
/// Returns the port part of this address.
|
||||
/// The port part of this address.
|
||||
pub extern "Lua-C" fn port(&self) -> u16 {
|
||||
self.0.port()
|
||||
}
|
||||
@ -775,16 +775,16 @@ impl lb_tcpstream {
|
||||
Ok(self.write.try_borrow_mut()?)
|
||||
}
|
||||
|
||||
/// Gets the remote socket address of this stream.
|
||||
pub extern "Lua-C" fn peer_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.read_half()?.peer_addr()?.into())
|
||||
}
|
||||
|
||||
/// Gets the local socket address of this stream.
|
||||
/// The local socket address that this stream is bound to.
|
||||
pub extern "Lua-C" fn local_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.read_half()?.local_addr()?.into())
|
||||
}
|
||||
|
||||
/// The remote socket address that this stream is connected to.
|
||||
pub extern "Lua-C" fn peer_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.read_half()?.peer_addr()?.into())
|
||||
}
|
||||
|
||||
/// Waits for this stream to be ready in the given half.
|
||||
///
|
||||
/// The argument `half` can be `"read"` for the readable half, `"write"` for the writable half,
|
||||
@ -936,7 +936,7 @@ impl lb_tcplistener {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the local socket address that this listener is bound to.
|
||||
/// The local socket address that this listener is bound to.
|
||||
pub extern "Lua-C" fn local_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.listener.local_addr()?.into())
|
||||
}
|
||||
@ -1019,12 +1019,12 @@ impl lb_tcplistener_stream {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the local socket address that the listener is bound to.
|
||||
/// The local socket address that the listener is bound to.
|
||||
pub extern "Lua-C" fn local_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.stream()?.local_addr()?.into())
|
||||
}
|
||||
|
||||
/// Returns the remote socket address of this stream.
|
||||
/// The remote socket address that this stream is connected to.
|
||||
pub extern "Lua-C" fn peer_addr(&self) -> Result<lb_socketaddr> {
|
||||
Ok(self.stream()?.peer_addr()?.into())
|
||||
}
|
||||
|
@ -645,7 +645,7 @@ impl<'r, 'm> MetatypeFunctionBuilder<'r, 'm> {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Annotation {
|
||||
pub trait Annotate {
|
||||
fn annotation() -> impl Display;
|
||||
}
|
||||
|
||||
@ -699,7 +699,7 @@ macro_rules! impl_primitive {
|
||||
fn build(_b: &mut TypeBuilder) {}
|
||||
}
|
||||
|
||||
impl Annotation for $rty {
|
||||
impl Annotate for $rty {
|
||||
fn annotation() -> impl Display {
|
||||
$lty
|
||||
}
|
||||
@ -867,9 +867,9 @@ impl_ptr!(Option<&mut T>, true);
|
||||
|
||||
macro_rules! impl_ref_annotation {
|
||||
($ty:ty) => {
|
||||
impl<T> Annotation for $ty
|
||||
impl<T> Annotate for $ty
|
||||
where
|
||||
T: Annotation,
|
||||
T: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("{}", T::annotation())
|
||||
@ -1005,9 +1005,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Annotation for [T]
|
||||
impl<T> Annotate for [T]
|
||||
where
|
||||
T: Annotation,
|
||||
T: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("{}[]", T::annotation())
|
||||
@ -1035,9 +1035,9 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, const N: usize> Annotation for [T; N]
|
||||
impl<T, const N: usize> Annotate for [T; N]
|
||||
where
|
||||
T: Annotation,
|
||||
T: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("{}[]", T::annotation())
|
||||
@ -1106,25 +1106,25 @@ impl_externcfn!(fn(A, B, C, D, E, F, G) -> H);
|
||||
impl_externcfn!(fn(A, B, C, D, E, F, G, H) -> I);
|
||||
impl_externcfn!(fn(A, B, C, D, E, F, G, H, I) -> J);
|
||||
|
||||
impl<'s> Annotation for &'s [u8] {
|
||||
impl<'s> Annotate for &'s [u8] {
|
||||
fn annotation() -> impl Display {
|
||||
"string"
|
||||
}
|
||||
}
|
||||
|
||||
impl<'s> Annotation for &'s str {
|
||||
impl<'s> Annotate for &'s str {
|
||||
fn annotation() -> impl Display {
|
||||
"string"
|
||||
}
|
||||
}
|
||||
|
||||
impl Annotation for Vec<u8> {
|
||||
impl Annotate for Vec<u8> {
|
||||
fn annotation() -> impl Display {
|
||||
"string"
|
||||
}
|
||||
}
|
||||
|
||||
impl Annotation for String {
|
||||
impl Annotate for String {
|
||||
fn annotation() -> impl Display {
|
||||
"string"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use crate::{
|
||||
__internal::{disp, display},
|
||||
Annotation,
|
||||
Annotate,
|
||||
};
|
||||
use std::{fmt::Display, marker::PhantomData};
|
||||
|
||||
@ -9,7 +9,7 @@ enum Marker {}
|
||||
|
||||
pub struct any(Marker);
|
||||
|
||||
impl Annotation for any {
|
||||
impl Annotate for any {
|
||||
fn annotation() -> impl Display {
|
||||
"any"
|
||||
}
|
||||
@ -17,7 +17,7 @@ impl Annotation for any {
|
||||
|
||||
pub struct many(Marker);
|
||||
|
||||
impl Annotation for many {
|
||||
impl Annotate for many {
|
||||
fn annotation() -> impl Display {
|
||||
"..."
|
||||
}
|
||||
@ -25,7 +25,7 @@ impl Annotation for many {
|
||||
|
||||
pub struct nil(Marker);
|
||||
|
||||
impl Annotation for nil {
|
||||
impl Annotate for nil {
|
||||
fn annotation() -> impl Display {
|
||||
"nil"
|
||||
}
|
||||
@ -33,7 +33,7 @@ impl Annotation for nil {
|
||||
|
||||
pub struct lightuserdata(Marker);
|
||||
|
||||
impl Annotation for lightuserdata {
|
||||
impl Annotate for lightuserdata {
|
||||
fn annotation() -> impl Display {
|
||||
"lightuserdata"
|
||||
}
|
||||
@ -41,10 +41,10 @@ impl Annotation for lightuserdata {
|
||||
|
||||
pub struct table<K, V>(Marker, PhantomData<*mut [(K, V)]>);
|
||||
|
||||
impl<K, V> Annotation for table<K, V>
|
||||
impl<K, V> Annotate for table<K, V>
|
||||
where
|
||||
K: Annotation,
|
||||
V: Annotation,
|
||||
K: Annotate,
|
||||
V: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("table<{}, {}>", K::annotation(), V::annotation())
|
||||
@ -53,7 +53,7 @@ where
|
||||
|
||||
pub struct function(Marker);
|
||||
|
||||
impl Annotation for function {
|
||||
impl Annotate for function {
|
||||
fn annotation() -> impl Display {
|
||||
"function"
|
||||
}
|
||||
@ -63,9 +63,9 @@ pub struct fun<I, O>(Marker, PhantomData<fn(I) -> O>);
|
||||
|
||||
macro_rules! impl_fun {
|
||||
(fn($($arg:ident),*)) => {
|
||||
impl<$($arg,)*> Annotation for fun<($($arg,)*), ()>
|
||||
impl<$($arg,)*> Annotate for fun<($($arg,)*), ()>
|
||||
where
|
||||
$($arg: Annotation,)*
|
||||
$($arg: Annotate,)*
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
disp(|f| {
|
||||
@ -79,10 +79,10 @@ macro_rules! impl_fun {
|
||||
};
|
||||
|
||||
(fn($($arg:ident),*) -> $ret:ident) => {
|
||||
impl<$($arg,)* $ret> Annotation for fun<($($arg,)*), $ret>
|
||||
impl<$($arg,)* $ret> Annotate for fun<($($arg,)*), $ret>
|
||||
where
|
||||
$($arg: Annotation,)*
|
||||
$ret: Annotation,
|
||||
$($arg: Annotate,)*
|
||||
$ret: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
disp(|f| {
|
||||
@ -111,7 +111,7 @@ impl_fun!(fn(A, B, C, D, E, F, G, H, I) -> J);
|
||||
|
||||
pub struct userdata(Marker);
|
||||
|
||||
impl Annotation for userdata {
|
||||
impl Annotate for userdata {
|
||||
fn annotation() -> impl Display {
|
||||
"userdata"
|
||||
}
|
||||
@ -119,7 +119,7 @@ impl Annotation for userdata {
|
||||
|
||||
pub struct thread(Marker);
|
||||
|
||||
impl Annotation for thread {
|
||||
impl Annotate for thread {
|
||||
fn annotation() -> impl Display {
|
||||
"thread"
|
||||
}
|
||||
@ -127,7 +127,7 @@ impl Annotation for thread {
|
||||
|
||||
pub struct cdata(Marker);
|
||||
|
||||
impl Annotation for cdata {
|
||||
impl Annotate for cdata {
|
||||
fn annotation() -> impl Display {
|
||||
"cdata"
|
||||
}
|
||||
@ -135,10 +135,10 @@ impl Annotation for cdata {
|
||||
|
||||
pub struct Either<T, U>(Marker, PhantomData<(T, U)>);
|
||||
|
||||
impl<T, U> Annotation for Either<T, U>
|
||||
impl<T, U> Annotate for Either<T, U>
|
||||
where
|
||||
T: Annotation,
|
||||
U: Annotation,
|
||||
T: Annotate,
|
||||
U: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("({} | {})", T::annotation(), U::annotation())
|
||||
@ -149,9 +149,9 @@ pub struct OneOf<X>(Marker, PhantomData<X>);
|
||||
|
||||
macro_rules! impl_oneof {
|
||||
($($ty:ident),+) => {
|
||||
impl<$($ty),+> Annotation for OneOf<($($ty,)+)>
|
||||
impl<$($ty),+> Annotate for OneOf<($($ty,)+)>
|
||||
where
|
||||
$($ty: Annotation),+
|
||||
$($ty: Annotate),+
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
disp(|f| {
|
||||
@ -174,18 +174,18 @@ impl_oneof!(A, B, C, D, E, F, G);
|
||||
impl_oneof!(A, B, C, D, E, F, G, H);
|
||||
impl_oneof!(A, B, C, D, E, F, G, H, I);
|
||||
|
||||
impl<T> Annotation for Option<T>
|
||||
impl<T> Annotate for Option<T>
|
||||
where
|
||||
T: Annotation,
|
||||
T: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("{}?", T::annotation())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Annotation for Result<T, E>
|
||||
impl<T, E> Annotate for Result<T, E>
|
||||
where
|
||||
T: Annotation,
|
||||
T: Annotate,
|
||||
{
|
||||
fn annotation() -> impl Display {
|
||||
display!("{}", T::annotation())
|
||||
|
@ -70,7 +70,7 @@ fn generate_type(ty: &Ident) -> Result<TokenStream> {
|
||||
}
|
||||
}
|
||||
|
||||
impl #ffi::Annotation for #ty {
|
||||
impl #ffi::Annotate for #ty {
|
||||
fn annotation() -> impl ::std::fmt::Display { #name }
|
||||
}
|
||||
|
||||
|
@ -682,7 +682,7 @@ fn stub_lua_function(func: &mut ImplItemFn) -> Result<()> {
|
||||
func.attrs.push(parse_quote!(#[allow(unused)]));
|
||||
func.block.stmts.clear();
|
||||
func.block.stmts.push(parse_quote!(
|
||||
const fn has_annotation<T: #ffi::Annotation>() {}
|
||||
const fn has_annotation<T: #ffi::Annotate>() {}
|
||||
));
|
||||
|
||||
// convert `...` variadic to a `rest: luaffi::marker::Many` parameter
|
||||
|
Loading…
x
Reference in New Issue
Block a user