Expand description
§SyncA
§Docs
§Example
#[synca::synca(
#[cfg(feature = "tokio")]
pub mod tokio { },
#[cfg(feature = "sync")]
pub mod sync {
sync!();
replace!(
tokio_postgres::Client => postgres::Client,
tokio_postgres::Error => postgres::Error,
#[tokio::test] => #[test]
);
}
)]
mod my_mod {
struct MyStruct {
client: tokio_postgres::Client
}
pub async fn get_name(client: &mut tokio_postgres::Client) -> String {
let row = self.client.query_one("SQL", &[]).await.unwrap();
row.get("name")
}
#[cfg(test)]
mod tests {
use super::get_name;
#[tokio::test]
pub async fn get_name_test() {
assert_eq!(get_name(&mut client()).await, "My name");
}
fn client() -> tokio_postgres::Client { todo!(); }
}
}
Generated code
#[cfg(feature = "tokio")]
pub mod tokio {
// Copy of my_mod content
}
#[cfg(feature = "sync")]
mod sync {
struct MyStruct {
client: postgres::Client
}
pub fn get_name(client: &mut postgres::Client) -> String {
let row = self.client.query_one("SQL", &[]).unwrap();
row.get("name")
}
#[cfg(test)]
mod tests {
use super::get_name;
#[test]
pub async fn get_name_test() {
assert_eq!(get_name(&mut client()), "My name");
}
fn client() -> postgres::Client { todo!(); }
}
}
Attribute Macros§
- Macro synca::synca