mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 13:19:18 +00:00
struct2 까지 해결
This commit is contained in:
parent
03a69236ba
commit
eb3e9dabb6
@ -3,11 +3,15 @@
|
|||||||
|
|
||||||
// I AM NOT DONE
|
// I AM NOT DONE
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct ColorClassicStruct {
|
struct ColorClassicStruct {
|
||||||
// TODO: Something goes here
|
// TODO: Something goes here
|
||||||
|
name:String,
|
||||||
|
hex:String,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ColorTupleStruct(/* TODO: Something goes here */);
|
|
||||||
|
struct ColorTupleStruct();
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct UnitStruct;
|
struct UnitStruct;
|
||||||
@ -19,7 +23,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn classic_c_structs() {
|
fn classic_c_structs() {
|
||||||
// TODO: Instantiate a classic c struct!
|
// TODO: Instantiate a classic c struct!
|
||||||
// let green =
|
let green = ColorClassicStruct{name:String::from("green"),
|
||||||
|
hex:String::from("#00FF00")};
|
||||||
|
|
||||||
assert_eq!(green.name, "green");
|
assert_eq!(green.name, "green");
|
||||||
assert_eq!(green.hex, "#00FF00");
|
assert_eq!(green.hex, "#00FF00");
|
||||||
@ -28,7 +33,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn tuple_structs() {
|
fn tuple_structs() {
|
||||||
// TODO: Instantiate a tuple struct!
|
// TODO: Instantiate a tuple struct!
|
||||||
// let green =
|
let green =(String::from("green"),String::from("#00FF00"));
|
||||||
|
|
||||||
assert_eq!(green.0, "green");
|
assert_eq!(green.0, "green");
|
||||||
assert_eq!(green.1, "#00FF00");
|
assert_eq!(green.1, "#00FF00");
|
||||||
@ -37,9 +42,16 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn unit_structs() {
|
fn unit_structs() {
|
||||||
// TODO: Instantiate a unit struct!
|
// TODO: Instantiate a unit struct!
|
||||||
// let unit_struct =
|
let unit_structs =String::from("UnitStructsss");
|
||||||
let message = format!("{:?}s are fun!", unit_struct);
|
let message = format!("{:?}s are fun!", unit_structs);
|
||||||
|
|
||||||
assert_eq!(message, "UnitStructs are fun!");
|
assert_eq!(message, "UnitStructs are fun!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let unit_structs =String::from("UnitStruct");
|
||||||
|
let message = format!("{:?}s are fun!", unit_structs);
|
||||||
|
println!("{}",message);
|
||||||
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ fn create_order_template() -> Order {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -34,7 +35,12 @@ mod tests {
|
|||||||
fn your_order() {
|
fn your_order() {
|
||||||
let order_template = create_order_template();
|
let order_template = create_order_template();
|
||||||
// TODO: Create your own order using the update syntax and template above!
|
// TODO: Create your own order using the update syntax and template above!
|
||||||
// let your_order =
|
let mut your_order=Order{
|
||||||
|
name:String::from("Hacker in Rust"),
|
||||||
|
..order_template
|
||||||
|
};
|
||||||
|
|
||||||
|
your_order.name=String::from("Hacker in Rust");
|
||||||
assert_eq!(your_order.name, "Hacker in Rust");
|
assert_eq!(your_order.name, "Hacker in Rust");
|
||||||
assert_eq!(your_order.year, order_template.year);
|
assert_eq!(your_order.year, order_template.year);
|
||||||
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
assert_eq!(your_order.made_by_phone, order_template.made_by_phone);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user