sonic-channel/src/lib.rs

92 lines
2.3 KiB
Rust
Raw Normal View History

2020-07-26 22:08:40 +03:00
//! # Sonic Channel
//! Rust client for [sonic] search backend.
//!
//!
//! ## Example usage
//!
//! ### Search channel
//!
//! Note: This example requires enabling the `search` feature, enabled by default.
2020-07-26 22:08:40 +03:00
//!
2020-08-01 11:04:54 +03:00
//! ```rust,no_run
2020-07-26 22:08:40 +03:00
//! use sonic_channel::*;
//!
//! fn main() -> result::Result<()> {
//! let channel = SonicChannel::connect_with_start(
//! ChannelMode::Search,
//! "localhost:1491",
//! "SecretPassword",
//! )?;
//!
//! let objects = channel.query("collection", "bucket", "recipe")?;
//! dbg!(objects);
//!
//! Ok(())
//! }
//! ```
//!
//! ### Ingest channel
//!
//! Note: This example requires enabling the `ingest` feature.
//!
2020-08-01 11:04:54 +03:00
//! ```rust,no_run
2020-07-26 22:08:40 +03:00
//! use sonic_channel::*;
//!
//! fn main() -> result::Result<()> {
//! let mut channel = SonicChannel::connect_with_start(
//! ChannelMode::Ingest,
//! "localhost:1491",
//! "SecretPassword",
//! )?;
//!
//! let pushed = channel.push("collection", "bucket", "object:1", "my best recipe")?;
//! // or
//! // let pushed = channel.push_with_locale("collection", "bucket", "object:1", "Мой лучший рецепт", "rus")?;
//! dbg!(pushed);
//!
//! Ok(())
//! }
//! ```
//!
//! [sonic]: https://github.com/valeriansaliou/sonic
// Rustc lints.
2020-07-18 11:01:51 +03:00
#![allow(dead_code)]
2020-07-26 22:08:40 +03:00
#![deny(
missing_debug_implementations,
unsafe_code,
unstable_features,
unused_imports,
unused_qualifications
)]
#![warn(missing_docs)]
2020-07-18 11:01:51 +03:00
2020-07-23 10:44:02 +03:00
#[cfg(not(any(feature = "ingest", feature = "search", feature = "control")))]
compile_error!(r#"Either features "ingest" or "search" or "control" must be enabled for "sonic-channel" crate"#);
2020-07-18 11:01:51 +03:00
mod channel;
mod commands;
2020-07-26 23:36:07 +03:00
/// Contains sonic channel error type and custom Result type for easy configure your functions.
pub mod result;
2020-07-18 11:01:51 +03:00
pub use channel::*;
#[macro_use]
extern crate lazy_static;
extern crate regex;
#[cfg(test)]
mod tests {
use crate::channel::ChannelMode;
#[test]
fn format_channel_enums() {
assert_eq!(format!("{}", ChannelMode::Search), String::from("search"));
assert_eq!(format!("{}", ChannelMode::Ingest), String::from("ingest"));
assert_eq!(format!("{}", ChannelMode::Control), String::from("control"));
}
//TODO: write tests with sonic server
}