This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Computer { | |
name: String, | |
serial: String, | |
cpu_cnt: u8, | |
ram_size: u64, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn build_computer_test() { | |
let computer = build_computer("apple".to_string(), "abcde-100".to_string()); | |
let copy_cat = Computer{ | |
name: "Capple".to_string(), | |
..computer | |
}; | |
println!("{:?}", copy_cat); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[test] | |
fn build_computer_test() { | |
let computer = build_computer("apple".to_string(), "abcde-100".to_string()); | |
println!("name {}", computer.name); | |
println!("serial {}", computer.serial); | |
println!("cpu_cnt {}", computer.cpu_cnt); | |
println!("ram_size {}", computer.ram_size); | |
let copy_cat = Computer{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn first_blank_finder(s: &String) -> Option<usize> { | |
let bytes = s.as_bytes(); | |
for (i, &item) in bytes.iter().enumerate() { | |
if item == b' ' { | |
Some(i) | |
} | |
} | |
Some(0 as usize) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn first_blank_finder(s: &String) -> Option<usize> { | |
let bytes = s.as_bytes(); | |
for (i, &item) in bytes.iter().enumerate() { | |
if item == b' ' { | |
return Some(i) | |
} | |
} | |
Some(0 as usize) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn search_foo(s: &String, word: &'static str) -> &'static str { | |
for (i, item) in s.chars().enumerate() { | |
if &s[i..i+3] == word { | |
return word | |
} | |
} | |
"" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mut s = String::from("hello world"); | |
let r1 = &s; | |
let r2 = &s; | |
let r3 = &mut s; | |
r3.push_str("Possible?"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import axios from "axios"; | |
import { getPosts } from "../services/postService"; | |
const apiEndpoint = "http://localhost:8000"; | |
class Posts extends Component { | |
state = { | |
count: 0, | |
next: "", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import axios from "axios"; | |
const apiEndpoint = "http://localhost:8000"; | |
class Posts extends Component { | |
state = { | |
posts: [] | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react"; | |
import axios from "axios"; | |
class Posts extends Component { | |
state = { | |
posts: [] | |
}; | |
async componentDidMount() { | |
const response = await axios.get("http://localhost:8000/posts"); |