Improve doc

This commit is contained in:
lumi 2025-06-27 23:47:52 +10:00
parent a760beabc1
commit 5f1f6dab7a
Signed by: luaneko
GPG Key ID: 406809B8763FF07A
2 changed files with 56 additions and 38 deletions

View File

@ -52,27 +52,27 @@ impl lb_netlib {
Self
}
/// See [`Ipv4Addr::LOCALHOST`].
/// An IPv4 address representing localhost: `127.0.0.1`
pub extern "Lua-C" fn localhost_v4(&self) -> lb_ipaddr {
lb_ipaddr(Ipv4Addr::LOCALHOST.into())
}
/// See [`Ipv6Addr::LOCALHOST`].
/// An IPv6 address representing localhost: `::1`
pub extern "Lua-C" fn localhost_v6(&self) -> lb_ipaddr {
lb_ipaddr(Ipv6Addr::LOCALHOST.into())
}
/// See [`Ipv4Addr::UNSPECIFIED`].
/// An IPv4 address representing an unspecified address: `0.0.0.0`
pub extern "Lua-C" fn unspecified_v4(&self) -> lb_ipaddr {
lb_ipaddr(Ipv4Addr::UNSPECIFIED.into())
}
/// See [`Ipv6Addr::UNSPECIFIED`].
/// An IPv6 address representing an unspecified address: `::`
pub extern "Lua-C" fn unspecified_v6(&self) -> lb_ipaddr {
lb_ipaddr(Ipv6Addr::UNSPECIFIED.into())
}
/// See [`Ipv4Addr::BROADCAST`].
/// An IPv4 address representing the broadcast address: `255.255.255.255`
pub extern "Lua-C" fn broadcast_v4(&self) -> lb_ipaddr {
lb_ipaddr(Ipv4Addr::BROADCAST.into())
}

View File

@ -798,55 +798,73 @@ fn inject_merged_drop(registry: &mut Registry, lua: Option<&LuaFunction>) -> Res
fn document_ffi_function(func: &mut ImplItemFn) {
func.attrs.insert(0, parse_quote!(#[doc =
r#"<span class="stab" title="This function is implemented in Rust and called via FFI." style="float: right; background: #fff5d6; font-weight: 500; margin-left: 3px; padding-left: 5px; padding-right: 5px;">FFI</span>"#
r#"<span
class="stab"
title="This function is implemented in Rust and called via FFI."
style="float: right; background: #fff5d6; font-weight: 500; margin-left: 3px; padding-left: 5px; padding-right: 5px;"
>FFI</span>"#
]));
}
fn document_lua_function(func: &mut ImplItemFn) {
func.attrs.insert(0, parse_quote!(#[doc =
r#"<span class="stab" title="This function is implemented in Lua." style="float: right; background: #ebf5ff; font-weight: 500; margin-left: 3px; padding-left: 5px; padding-right: 5px;">Lua</span>"#
r#"<span
class="stab"
title="This function is implemented in Lua."
style="float: right; background: #ebf5ff; font-weight: 500; margin-left: 3px; padding-left: 5px; padding-right: 5px;"
>Lua</span>"#
]));
}
fn document_async(func: &mut ImplItemFn) {
func.attrs.insert(0, parse_quote!(#[doc =
r#"<span class="stab" title="This function is asynchronous." style="float: right; background: #ebf5ff; margin-left: 3px; padding-left: 5px; padding-right: 5px;">Async</span>"#
r#"<span
class="stab"
title="This function is asynchronous and will yield the calling thread."
style="float: right; background: #ebf5ff; margin-left: 3px; padding-left: 5px; padding-right: 5px;"
>Async</span>"#
]));
}
fn document_metamethod(func: &mut ImplItemFn, method: Metamethod) {
let s = match method {
Metamethod::Eq => "This is a metamethod which is called by the `==` operator.",
Metamethod::Len => "This is a metamethod which is called by the `#` operator.",
Metamethod::Lt => "This is a metamethod which is called by the `<` operator.",
Metamethod::Le => "This is a metamethod which is called by the `<=` operator.",
Metamethod::Concat => "This is a metamethod which is called by the `..` operator.",
Metamethod::Call => {
"This is a metamethod which can be called by calling `(...)` on the value directly."
}
Metamethod::Add => "This is a metamethod which is called by the `+` operator.",
Metamethod::Sub => "This is a metamethod which is called by the `-` operator.",
Metamethod::Mul => "This is a metamethod which is called by the `*` operator.",
Metamethod::Div => "This is a metamethod which is called by the `/` operator.",
Metamethod::Mod => "This is a metamethod which is called by the `%` operator.",
Metamethod::Pow => "This is a metamethod which is called by the `^` operator.",
Metamethod::Unm => "This is a metamethod which is called by the `-` operator.",
Metamethod::ToString => {
"This is a metamethod which is called by the [`tostring(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-tostring) built-in function."
}
Metamethod::Pairs => {
"This is a metamethod which is called by the [`pairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-pairs) built-in function."
}
Metamethod::Ipairs => {
"This is a metamethod which is called by the [`ipairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-ipairs) built-in function."
}
_ => "This is a metamethod and cannot be called directly.",
};
func.attrs.insert(0, parse_quote!(#[doc =
r#"<span class="stab" title="This function is a metamethod." style="float: right; background: #ebf5ff; margin-left: 3px; padding-left: 5px; padding-right: 5px;">Metamethod</span>"#
r#"<span
class="stab"
title="This function is a metamethod."
style="float: right; background: #ebf5ff; margin-left: 3px; padding-left: 5px; padding-right: 5px;"
>Metamethod</span>"#
]));
let doc = match method {
Metamethod::Eq => "This function is a metamethod which is called by the `==` operator.",
Metamethod::Len => "This function is a metamethod which is called by the `#` operator.",
Metamethod::Lt => "This function is a metamethod which is called by the `<` operator.",
Metamethod::Le => "This function is a metamethod which is called by the `<=` operator.",
Metamethod::Concat => "This function is a metamethod which is called by the `..` operator.",
Metamethod::Call => {
"This function is a metamethod which can be called by calling `(...)` on the value directly."
}
Metamethod::Add => "This function is a metamethod which is called by the `+` operator.",
Metamethod::Sub => "This function is a metamethod which is called by the `-` operator.",
Metamethod::Mul => "This function is a metamethod which is called by the `*` operator.",
Metamethod::Div => "This function is a metamethod which is called by the `/` operator.",
Metamethod::Mod => "This function is a metamethod which is called by the `%` operator.",
Metamethod::Pow => "This function is a metamethod which is called by the `^` operator.",
Metamethod::Unm => "This function is a metamethod which is called by the `-` operator.",
Metamethod::ToString => {
"This function is a metamethod which is called by the [`tostring(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-tostring) built-in function."
}
Metamethod::Pairs => {
"This function is a metamethod which is called by the [`pairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-pairs) built-in function."
}
Metamethod::Ipairs => {
"This function is a metamethod which is called by the [`ipairs(...)`](https://www.lua.org/manual/5.1/manual.html#pdf-ipairs) built-in function."
}
_ => "This function is a metamethod and cannot be called directly.",
};
func.attrs.push(parse_quote!(#[doc = ""]));
func.attrs.push(parse_quote!(#[doc = #s]));
func.attrs.push(parse_quote!(#[doc = "# Metamethod"]));
func.attrs.push(parse_quote!(#[doc = ""]));
func.attrs.push(parse_quote!(#[doc = #doc]));
}