Skip to content

Commit

Permalink
[breaking-change]: Re-export public types in the crate root.
Browse files Browse the repository at this point in the history
This makes all internal modules private, and only exposes a bunch of
public structs.
To fix your code, where it says “struct `...` is private”, just remove
preceding module name, for example:
```
examples/consumer.rs:4:5: 4:27 error: struct `Session` is private
examples/consumer.rs:4 use amqp::session::Session;
```
change line to:
```
use amqp::Session;
```
  • Loading branch information
Antti committed Oct 13, 2015
1 parent 521105a commit 2a3cea6
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 62 deletions.
16 changes: 16 additions & 0 deletions Changelog.md
@@ -0,0 +1,16 @@
# 0.0.12

Re-exported types from sub-modules to a crate level.
Made most of the internals private. Made public only necessary things.

Upgrading, in most cases requires removing preceding module name before struct:
```rust
use amqp::session::Session;
use amqp::basic::Basic;
use amqp::channel::Channel;
```
will become something like:
```rust
use amqp::{Session, Basic, Channel};
```
The only things where you still use modules of are `protocol` and `table`.
5 changes: 2 additions & 3 deletions Readme.md
Expand Up @@ -20,8 +20,7 @@ Have a look at the examples in `examples/` folder.

```rust
extern crate amqp;
use amqp::session::Session;
use amqp::table;
use amqp::Session;

let mut session = Session::open_url("amqp://localhost/").unwrap();
let mut channel = session.open_channel(1).unwrap();
Expand All @@ -34,7 +33,7 @@ let mut channel = session.open_channel(1).unwrap();
```rust
//The arguments come in following order:
//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let queue_declare = channel.queue_declare("my_queue_name", false, true, false, false, false, table::new());
let queue_declare = channel.queue_declare("my_queue_name", false, true, false, false, false, Table::new());
```

### Publishing message:
Expand Down
2 changes: 1 addition & 1 deletion codegen.rb
Expand Up @@ -188,7 +188,7 @@ def value_to_rust_value(value)
when TrueClass, FalseClass
value
when Hash
"table::new()"
"Table::new()"
else
raise "Cant convert value #{value}"
end
Expand Down
15 changes: 5 additions & 10 deletions examples/consumer.rs
@@ -1,12 +1,7 @@
extern crate amqp;
extern crate env_logger;

use amqp::session::Options;
use amqp::session::Session;
use amqp::protocol;
use amqp::table;
use amqp::basic::Basic;
use amqp::channel::{Channel, ConsumerCallBackFn};
use amqp::{Session, Options, Table, Basic, protocol, Channel, ConsumerCallBackFn, Consumer};
use std::default::Default;

fn consumer_function(channel: &mut Channel, deliver: protocol::basic::Deliver, headers: protocol::basic::BasicProperties, body: Vec<u8>){
Expand All @@ -22,7 +17,7 @@ struct MyConsumer {
deliveries_number: u64
}

impl amqp::channel::Consumer for MyConsumer {
impl amqp::Consumer for MyConsumer {
fn handle_delivery(&mut self, channel: &mut Channel, deliver: protocol::basic::Deliver, headers: protocol::basic::BasicProperties, body: Vec<u8>){
println!("[struct] Got a delivery # {}", self.deliveries_number);
println!("[struct] Deliver info: {:?}", deliver);
Expand All @@ -43,16 +38,16 @@ fn main() {

let queue_name = "test_queue";
//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, table::new());
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, Table::new());

println!("Queue declare: {:?}", queue_declare);
channel.basic_prefetch(10).ok().expect("Failed to prefetch");
//consumer, queue: &str, consumer_tag: &str, no_local: bool, no_ack: bool, exclusive: bool, nowait: bool, arguments: Table
println!("Declaring consumer...");
let consumer_name = channel.basic_consume(consumer_function as ConsumerCallBackFn, queue_name, "", false, false, false, false, table::new());
let consumer_name = channel.basic_consume(consumer_function as ConsumerCallBackFn, queue_name, "", false, false, false, false, Table::new());
println!("Starting consumer {:?}", consumer_name);
let my_consumer = MyConsumer { deliveries_number: 0 };
let consumer_name = channel.basic_consume(my_consumer, queue_name, "", false, false, false, false, table::new());
let consumer_name = channel.basic_consume(my_consumer, queue_name, "", false, false, false, false, Table::new());

println!("Starting consumer {:?}", consumer_name);
channel.start_consuming();
Expand Down
10 changes: 4 additions & 6 deletions examples/exchange_bind.rs
@@ -1,9 +1,7 @@
extern crate amqp;
extern crate env_logger;

use amqp::session::Options;
use amqp::session::Session;
use amqp::table;
use amqp::{Session, Options, Table};
use std::default::Default;


Expand All @@ -19,14 +17,14 @@ fn main() {

//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let exchange_declare1 = channel.exchange_declare(exchange1, exchange_type,
false, true, false, false, false, table::new());
false, true, false, false, false, Table::new());

println!("Exchange declare: {:?}", exchange_declare1);
let exchange_declare2 = channel.exchange_declare(exchange2, exchange_type,
false, true, false, false, false, table::new());
false, true, false, false, false, Table::new());
println!("Exchange declare: {:?}", exchange_declare2);

let bind_reply = channel.exchange_bind(exchange1, exchange2, "#", table::new());
let bind_reply = channel.exchange_bind(exchange1, exchange2, "#", Table::new());
println!("Exchange bind: {:?}", bind_reply);


Expand Down
7 changes: 2 additions & 5 deletions examples/interactive.rs
@@ -1,10 +1,7 @@
extern crate amqp;
extern crate env_logger;

use amqp::session::Session;
use amqp::protocol;
use amqp::table;
use amqp::basic::Basic;
use amqp::{Session, Table, Basic, protocol};
use std::default::Default;
use std::io;

Expand All @@ -20,7 +17,7 @@ fn main() {
let mut channel = session.open_channel(1).ok().expect("Can't open channel!");

let queue_name = "test_queue";
channel.queue_declare(queue_name, false, true, false, false, false, table::new()).ok().expect("Unable to declare queue!");
channel.queue_declare(queue_name, false, true, false, false, false, Table::new()).ok().expect("Unable to declare queue!");

println!("Type some text here below, it will be sent into the '{}' queue. Hit Enter when done.", queue_name);
let mut input_data = String::new();
Expand Down
8 changes: 2 additions & 6 deletions examples/producer.rs
@@ -1,11 +1,7 @@
extern crate amqp;
extern crate env_logger;

use amqp::session::Options;
use amqp::session::Session;
use amqp::protocol;
use amqp::table;
use amqp::basic::Basic;
use amqp::{Session, Options, Table, Basic, protocol};
use std::default::Default;

extern "C" {
Expand All @@ -27,7 +23,7 @@ fn main() {

let queue_name = "test_queue";
//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, table::new());
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, Table::new());
println!("Queue declare: {:?}", queue_declare);

unsafe {
Expand Down
11 changes: 4 additions & 7 deletions examples/simple.rs
@@ -1,11 +1,7 @@
extern crate amqp;
extern crate env_logger;

use amqp::session::Session;
use amqp::protocol;
use amqp::table;
use amqp::basic::Basic;
use amqp::channel::{Channel, ConsumerCallBackFn};
use amqp::{Basic, Session, Channel, ConsumerCallBackFn, Table, protocol};
use std::default::Default;
use std::thread;

Expand All @@ -22,6 +18,7 @@ fn consumer_function(channel: &mut Channel, deliver: protocol::basic::Deliver, h

fn main() {
env_logger::init().unwrap();
let amqp_url = "amqp://xbisgjql:CmWhamjl6jasNNM6OVJOxiiy0yGdDjt2@bunny.cloudamqp.com/xbisgjql";
let amqp_url = "amqp://guest:guest@127.0.0.1//";
let mut session = match Session::open_url(amqp_url) {
Ok(session) => session,
Expand All @@ -32,7 +29,7 @@ fn main() {

let queue_name = "test_queue";
//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, table::new());
let queue_declare = channel.queue_declare(queue_name, false, true, false, false, false, Table::new());
println!("Queue declare: {:?}", queue_declare);
for get_result in channel.basic_get(queue_name, false) {
println!("Headers: {:?}", get_result.headers);
Expand All @@ -43,7 +40,7 @@ fn main() {

//queue: &str, consumer_tag: &str, no_local: bool, no_ack: bool, exclusive: bool, nowait: bool, arguments: Table
println!("Declaring consumer...");
let consumer_name = channel.basic_consume(consumer_function as ConsumerCallBackFn, queue_name, "", false, false, false, false, table::new());
let consumer_name = channel.basic_consume(consumer_function as ConsumerCallBackFn, queue_name, "", false, false, false, false, Table::new());
println!("Starting consumer {:?}", consumer_name);

let consumers_thread = thread::spawn(move || {
Expand Down
3 changes: 1 addition & 2 deletions src/basic.rs
Expand Up @@ -112,8 +112,7 @@ impl <'a> Basic<'a> for Channel {
/// # Example
/// ```no_run
/// use std::default::Default;
/// use amqp::session::{Options, Session};
/// use amqp::basic::Basic;
/// use amqp::{Options, Session, Basic};
/// let mut session = match Session::new(Options { .. Default::default() }){
/// Ok(session) => session,
/// Err(error) => panic!("Failed openning an amqp session: {:?}", error)
Expand Down
20 changes: 13 additions & 7 deletions src/lib.rs
Expand Up @@ -83,11 +83,17 @@ extern crate log;

#[macro_use] extern crate enum_primitive;

pub mod connection;
pub mod channel;
pub mod framing;
pub mod table;
mod connection;
mod channel;
mod framing;
mod session;
mod basic;
mod amqp_error;

pub mod protocol;
pub mod session;
pub mod basic;
pub mod amqp_error;
pub mod table;

pub use session::{Session, Options};
pub use channel::{Channel, ConsumerCallBackFn, Consumer};
pub use table::Table;
pub use basic::{Basic, GetResult};
14 changes: 7 additions & 7 deletions src/protocol.rs
Expand Up @@ -1324,7 +1324,7 @@ pub mod exchange {
Declare {
ticket: 0,
_type: "direct".to_string(),
arguments: table::new(),
arguments: Table::new(),
exchange: exchange,
passive: passive,
durable: durable,
Expand Down Expand Up @@ -1550,7 +1550,7 @@ pub mod exchange {
Bind {
ticket: 0,
routing_key: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
destination: destination,
source: source,
nowait: nowait,
Expand Down Expand Up @@ -1670,7 +1670,7 @@ pub mod exchange {
Unbind {
ticket: 0,
routing_key: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
destination: destination,
source: source,
nowait: nowait,
Expand Down Expand Up @@ -1812,7 +1812,7 @@ pub mod queue {
Declare {
ticket: 0,
queue: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
passive: passive,
durable: durable,
exclusive: exclusive,
Expand Down Expand Up @@ -1953,7 +1953,7 @@ pub mod queue {
ticket: 0,
queue: "".to_string(),
routing_key: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
exchange: exchange,
nowait: nowait,
}
Expand Down Expand Up @@ -2281,7 +2281,7 @@ pub mod queue {
ticket: 0,
queue: "".to_string(),
routing_key: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
exchange: exchange,
}
}
Expand Down Expand Up @@ -2795,7 +2795,7 @@ pub mod basic {
ticket: 0,
queue: "".to_string(),
consumer_tag: "".to_string(),
arguments: table::new(),
arguments: Table::new(),
no_local: no_local,
no_ack: no_ack,
exclusive: exclusive,
Expand Down
10 changes: 5 additions & 5 deletions src/session.rs
@@ -1,7 +1,7 @@
use channel;
use connection::Connection;
use protocol::{self, MethodFrame};
use table;
use table::Table;
use table::TableEntry::{FieldTable, Bool, LongString};
use framing::Frame;
use amqp_error::{AMQPResult, AMQPError};
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Session {
/// # Example
/// ```no_run
/// use std::default::Default;
/// use amqp::session::{Options, Session};
/// use amqp::{Options, Session};
/// let session = match Session::new(Options { .. Default::default() }){
/// Ok(session) => session,
/// Err(error) => panic!("Failed openning an amqp session: {:?}", error)
Expand Down Expand Up @@ -144,8 +144,8 @@ impl Session {
// the response consist of a login name and password.
// * The server repeats the challenge (Secure) or moves to negotiation, sending a set of parameters such as

let mut client_properties = table::new();
let mut capabilities = table::new();
let mut client_properties = Table::new();
let mut capabilities = Table::new();
capabilities.insert("publisher_confirms".to_string(), Bool(true));
capabilities.insert("consumer_cancel_notify".to_string(), Bool(true));
capabilities.insert("exchange_exchange_bindings".to_string(), Bool(true));
Expand Down Expand Up @@ -199,7 +199,7 @@ impl Session {
/// # Exmaple
/// ```no_run
/// use std::default::Default;
/// use amqp::session::{Options, Session};
/// use amqp::{Options, Session};
/// let mut session = Session::new(Options { .. Default::default() }).ok().unwrap();
/// let channel = match session.open_channel(1){
/// Ok(channel) => channel,
Expand Down
12 changes: 9 additions & 3 deletions src/table.rs
Expand Up @@ -28,8 +28,14 @@ pub enum TableEntry {

pub type Table = HashMap<String, TableEntry>;

pub fn new() -> Table {
HashMap::new()
pub trait Init {
fn new() -> Self;
}

impl Init for Table {
fn new() -> Self {
HashMap::new()
}
}

fn read_table_entry(reader: &mut &[u8]) -> AMQPResult<TableEntry> {
Expand Down Expand Up @@ -121,7 +127,7 @@ fn write_table_entry(writer: &mut Vec<u8>, table_entry: &TableEntry) -> AMQPResu

pub fn decode_table(reader: &mut &[u8]) -> AMQPResult<Table> {
debug!("decoding table");
let mut table = new();
let mut table = Table::new();
let size = try!(reader.read_u32::<BigEndian>()) as usize;
let total_len = reader.len();

Expand Down

0 comments on commit 2a3cea6

Please sign in to comment.