Skip to content

example

Jared Fowler edited this page Apr 14, 2018 · 1 revision

examples

example sketch of how this crate is used: A crate for the binary, which imports a crate (the lib); using like this?

src/main.rs

extern crate awl;

use awl::Awl;

fn main() {
    println!("awl is a tool to punch holes with.");
    let a = Awl {
        ip_addr: "127.0.0.1".to_string(),
        port: 1337
    };

    a.my_ip();
}

and in src/lib.rs, we declare the Awl struct that implements client and server methods:

/// Main constructor.
pub struct Awl {
   pub ip_addr: String,
   pub port: u16,
}

impl Awl {
    pub fn my_ip(&self) {
       println!("My IP is {}", self.ip_addr);
    }
}
/// client / server / connnections here or created as own mods (probably better) and imported

Clone this wiki locally