diff --git a/crates/lb/src/fs.rs b/crates/lb/src/fs.rs index b6a83a5..5e6a9a4 100644 --- a/crates/lb/src/fs.rs +++ b/crates/lb/src/fs.rs @@ -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> { 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> { 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 { 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 { 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 { 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 { 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> { 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> { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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> { 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 { 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> { while let Some(res) = self.iter.try_borrow_mut()?.next() { diff --git a/crates/lb/src/net.rs b/crates/lb/src/net.rs index 943b205..606613a 100644 --- a/crates/lb/src/net.rs +++ b/crates/lb/src/net.rs @@ -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 { - 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 { 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 { + 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 { 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 { 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 { Ok(self.stream()?.peer_addr()?.into()) } diff --git a/crates/luaffi/src/lib.rs b/crates/luaffi/src/lib.rs index e243b94..93ec583 100644 --- a/crates/luaffi/src/lib.rs +++ b/crates/luaffi/src/lib.rs @@ -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 Annotation for $ty + impl Annotate for $ty where - T: Annotation, + T: Annotate, { fn annotation() -> impl Display { display!("{}", T::annotation()) @@ -1005,9 +1005,9 @@ where } } -impl Annotation for [T] +impl Annotate for [T] where - T: Annotation, + T: Annotate, { fn annotation() -> impl Display { display!("{}[]", T::annotation()) @@ -1035,9 +1035,9 @@ where } } -impl Annotation for [T; N] +impl 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 { +impl Annotate for Vec { fn annotation() -> impl Display { "string" } } -impl Annotation for String { +impl Annotate for String { fn annotation() -> impl Display { "string" } diff --git a/crates/luaffi/src/marker.rs b/crates/luaffi/src/marker.rs index 48d79ff..b6dad2e 100644 --- a/crates/luaffi/src/marker.rs +++ b/crates/luaffi/src/marker.rs @@ -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(Marker, PhantomData<*mut [(K, V)]>); -impl Annotation for table +impl Annotate for table 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(Marker, PhantomData 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(Marker, PhantomData<(T, U)>); -impl Annotation for Either +impl Annotate for Either 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(Marker, PhantomData); 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 Annotation for Option +impl Annotate for Option where - T: Annotation, + T: Annotate, { fn annotation() -> impl Display { display!("{}?", T::annotation()) } } -impl Annotation for Result +impl Annotate for Result where - T: Annotation, + T: Annotate, { fn annotation() -> impl Display { display!("{}", T::annotation()) diff --git a/crates/luaffi_impl/src/cdef.rs b/crates/luaffi_impl/src/cdef.rs index dc46f08..9c0b7a4 100644 --- a/crates/luaffi_impl/src/cdef.rs +++ b/crates/luaffi_impl/src/cdef.rs @@ -70,7 +70,7 @@ fn generate_type(ty: &Ident) -> Result { } } - impl #ffi::Annotation for #ty { + impl #ffi::Annotate for #ty { fn annotation() -> impl ::std::fmt::Display { #name } } diff --git a/crates/luaffi_impl/src/metatype.rs b/crates/luaffi_impl/src/metatype.rs index 7eb6d27..1a346cb 100644 --- a/crates/luaffi_impl/src/metatype.rs +++ b/crates/luaffi_impl/src/metatype.rs @@ -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() {} + const fn has_annotation() {} )); // convert `...` variadic to a `rest: luaffi::marker::Many` parameter