1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! # Sonic Channel
//! Rust client for [sonic] search backend.
//! 
//! 
//! ## Example usage
//! 
//! ### Search channel
//!
//! Note: This example requires enabling the `search` feature, enabled by default.
//! 
//! ```rust,no_run
//! 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.
//!
//! ```rust,no_run
//! 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.
#![allow(dead_code)]
#![deny(
    missing_debug_implementations,
    unsafe_code,
    unstable_features,
    unused_imports,
    unused_qualifications
)]
#![warn(missing_docs)]

#[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"#);

mod channel;
mod commands;

/// Contains sonic channel error type and custom Result type for easy configure your functions.
pub mod result;

pub use channel::*;
pub use commands::*;

#[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
}