Rust モジュール

fn three_times(x: i32) -> i32 {
	x * 3
}

fn main() {
	
	for i in 1..4 {
		println!("{}の3倍={}", i, three_times(i));
	}
}

//modsample/src/myutil.rs

pub fn three_times(x: i32) -> i32 {
	x * 3
}
mod myutil;

fn main() {
	
	for i in 1..4 {
		println!("{}の3倍={}", i, myutil ::three_times(i));
	}
}

### ライブラリ
独立したライブラリの作成
$ cargo new mysamplelib –lib

pub fn half(x: i32) -> i32 {
	x / 2
}
use mysamplelib;

fn main() {
	let x = 12;
	let y = mysamplelib::half(x);
	println!("{}の半分は{}", x, y);
}
[package]
name="testmylib"
version = "0.1.0"
authors = ["notes"]
edition = ""

reference/manifest.html

[dependencies]
mysamplelib = {path = "../mysamplelib"}