Skip to content

Commit 7f7ddb8

Browse files
author
Mingshen Sun
committed
Add a dummy utility to demonstrate the framework
1 parent ea0bcb4 commit 7f7ddb8

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ sysinit = [
6060
"init"
6161
]
6262

63+
# a dummy utility to help people to understand the framework
64+
dummy = ["libmesabox/dummy"]
65+
other = [
66+
"dummy"
67+
]
68+
6369
# utilities that work on Unix
6470
unix = [
6571
"gnu",

libmesabox/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ sysinit = [
5858
"init"
5959
]
6060

61+
# a dummy utility to help people to understand the framework
62+
dummy = []
63+
other = [
64+
"dummy"
65+
]
66+
6167
# utilities that work on Unix
6268
unix = [
6369
"gnu",

libmesabox/src/other/dummy.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Copyright (c) 2018, The MesaLock Linux Project Contributors
3+
// All rights reserved.
4+
//
5+
// This work is licensed under the terms of the BSD 3-Clause License.
6+
// For a copy, see the LICENSE file.
7+
//
8+
9+
use {UtilSetup, ArgsIter, Result, UtilRead, UtilWrite};
10+
use std::io::{self, Write};
11+
12+
pub const DESCRIPTION: &str = "A dummy utility to demonstrate the framework";
13+
14+
#[derive(Fail, Debug)]
15+
enum DummyError {
16+
#[fail(display = "something wrong")]
17+
SomethingWrong
18+
}
19+
20+
type DummyResult<T> = ::std::result::Result<T, DummyError>;
21+
22+
struct Dummyer<O>
23+
where
24+
O: Write
25+
{
26+
output: O
27+
}
28+
29+
impl<O> Dummyer<O>
30+
where
31+
O: Write
32+
{
33+
fn new(output: O) -> Self {
34+
Dummyer { output }
35+
}
36+
37+
fn dummy(&mut self) -> DummyResult<()> {
38+
writeln!(self.output, "write something to the output");
39+
Ok(())
40+
}
41+
}
42+
43+
pub fn execute<S, T>(setup: &mut S, _args: T) -> Result<()>
44+
where
45+
S: UtilSetup,
46+
T: ArgsIter,
47+
{
48+
let output = setup.output();
49+
let mut output = output.lock()?;
50+
let mut dummyer = Dummyer::new(output);
51+
dummyer.dummy()?;
52+
Ok(())
53+
}

libmesabox/src/util_list.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@ generate_fns! {
2727
},
2828
sysinit {
2929
(init, "init")
30+
},
31+
other {
32+
(dummy, "dummy")
3033
}
3134
}

0 commit comments

Comments
 (0)