chore (macro-rs): ts_only_warn -> ts_export
This commit is contained in:
parent
4bb6f6e0e3
commit
1f082bfb56
5 changed files with 13 additions and 73 deletions
|
@ -48,14 +48,12 @@ impl From<Acct> for String {
|
|||
}
|
||||
}
|
||||
|
||||
#[crate::ts_only_warn("Use `acct.parse().unwrap()` or `Acct::from_str(acct).unwrap()` instead.")]
|
||||
#[crate::export]
|
||||
#[crate::ts_export]
|
||||
pub fn string_to_acct(acct: &str) -> Acct {
|
||||
Acct::from_str(acct).unwrap()
|
||||
}
|
||||
|
||||
#[crate::ts_only_warn("Use `acct.to_string()` instead.")]
|
||||
#[crate::export]
|
||||
#[crate::ts_export]
|
||||
pub fn acct_to_string(acct: &Acct) -> String {
|
||||
acct.to_string()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub use macro_rs::{export, ts_only_warn};
|
||||
pub use macro_rs::{export, ts_export};
|
||||
|
||||
pub mod config;
|
||||
pub mod database;
|
||||
|
|
|
@ -1,33 +1,4 @@
|
|||
#[crate::ts_only_warn("Use `emojis::get(str).is_some()` instead.")]
|
||||
#[crate::export]
|
||||
#[crate::ts_export]
|
||||
pub fn is_unicode_emoji(s: &str) -> bool {
|
||||
emojis::get(s).is_some()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod unit_test {
|
||||
#[allow(deprecated)]
|
||||
use super::is_unicode_emoji;
|
||||
|
||||
#[test]
|
||||
#[allow(deprecated)]
|
||||
fn test_unicode_emoji_check() {
|
||||
assert!(is_unicode_emoji("⭐"));
|
||||
assert!(is_unicode_emoji("👍"));
|
||||
assert!(is_unicode_emoji("❤"));
|
||||
assert!(is_unicode_emoji("♥️"));
|
||||
assert!(is_unicode_emoji("❤️"));
|
||||
assert!(is_unicode_emoji("💙"));
|
||||
assert!(is_unicode_emoji("🩷"));
|
||||
assert!(is_unicode_emoji("🖖🏿"));
|
||||
assert!(is_unicode_emoji("🏃➡️"));
|
||||
assert!(is_unicode_emoji("👩❤️👨"));
|
||||
assert!(is_unicode_emoji("👩👦👦"));
|
||||
assert!(is_unicode_emoji("🏳️🌈"));
|
||||
|
||||
assert!(!is_unicode_emoji("⭐⭐"));
|
||||
assert!(!is_unicode_emoji("x"));
|
||||
assert!(!is_unicode_emoji("\t"));
|
||||
assert!(!is_unicode_emoji(":meow_aww:"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,12 +130,12 @@ pub async fn nodeinfo_2_0() -> Result<Nodeinfo20, Error> {
|
|||
Ok(nodeinfo_2_1().await?.into())
|
||||
}
|
||||
|
||||
#[crate::export(js_name = "nodeinfo_2_1")]
|
||||
#[crate::ts_export(js_name = "nodeinfo_2_1")]
|
||||
pub async fn nodeinfo_2_1_as_json() -> Result<serde_json::Value, Error> {
|
||||
Ok(serde_json::to_value(nodeinfo_2_1().await?)?)
|
||||
}
|
||||
|
||||
#[crate::export(js_name = "nodeinfo_2_0")]
|
||||
#[crate::ts_export(js_name = "nodeinfo_2_0")]
|
||||
pub async fn nodeinfo_2_0_as_json() -> Result<serde_json::Value, Error> {
|
||||
Ok(serde_json::to_value(nodeinfo_2_0().await?)?)
|
||||
}
|
||||
|
|
|
@ -33,49 +33,20 @@ pub fn export(
|
|||
.into()
|
||||
}
|
||||
|
||||
/// Denotes that this function should only be used in TypeScript.
|
||||
///
|
||||
/// # Example
|
||||
/// ```
|
||||
/// # use macro_rs::ts_only_warn;
|
||||
/// # use std::fmt::{Display, Formatter, Result};
|
||||
/// # pub struct Thing {}
|
||||
/// # impl Display for Thing { fn fmt(&self, fmt: &mut Formatter) -> Result { Ok(()) } } // dummy
|
||||
/// #[ts_only_warn("Use `thing.to_string()` instead.")]
|
||||
/// pub fn thing_to_string(thing: Thing) -> String {
|
||||
/// thing.to_string()
|
||||
/// }
|
||||
/// ```
|
||||
/// generates
|
||||
/// ```
|
||||
/// # use macro_rs::ts_only_warn;
|
||||
/// # use std::fmt::{Display, Formatter, Result};
|
||||
/// # pub struct Thing {}
|
||||
/// # impl Display for Thing { fn fmt(&self, fmt: &mut Formatter) -> Result { Ok(()) } } // dummy
|
||||
/// #[cfg_attr(not(feature = "napi"), deprecated = "This function is only for TypeScript export. Use `thing.to_string()` instead.")]
|
||||
/// pub fn thing_to_string(thing: Thing) -> String {
|
||||
/// thing.to_string()
|
||||
/// }
|
||||
/// ```
|
||||
/// Export this function, struct, enum, const, etc. to TypeScript
|
||||
/// and make it unable to use in Rust
|
||||
#[proc_macro_attribute]
|
||||
pub fn ts_only_warn(
|
||||
pub fn ts_export(
|
||||
attr: proc_macro::TokenStream,
|
||||
item: proc_macro::TokenStream,
|
||||
) -> proc_macro::TokenStream {
|
||||
let attr: TokenStream = attr.into();
|
||||
let item: TokenStream = item.into();
|
||||
|
||||
let attr_str = Into::<TokenStream>::into(attr).to_string();
|
||||
let msg = {
|
||||
let mut chars = attr_str.as_str().chars();
|
||||
chars.next();
|
||||
chars.next_back();
|
||||
chars.as_str()
|
||||
};
|
||||
let prefixed_msg = format!("This function is only for TypeScript export. {}", msg);
|
||||
|
||||
quote! {
|
||||
#[cfg_attr(not(feature = "napi"), deprecated = #prefixed_msg)]
|
||||
#item
|
||||
#[cfg(feature = "napi")]
|
||||
#[macro_rs::napi(#attr)]
|
||||
#item
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue