luvit 스터디 중간 중간의 기록
Programming language design is often thought of in terms of which features you include, but the features you exclude are important too. Rust doesn’t have the null feature that many other languages have. Null is a value that means there is no value there. In languages with null, variables can always be in one of two states: null or not-null.
In his 2009 presentation “Null References: The Billion Dollar Mistake,” Tony Hoare, the inventor of null, has this to say:
I call it my billion-dollar mistake. At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn’t resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.
https://doc.rust-lang.org/book/
이 패키지는 2025.2월에 시행된 웹 서버 프레임워크에 대한 성능 벤치마킹 테스트에서 7위, Fullstack을 지원하는 프레임워크로 한정하면 2위를 차지한, 현존하는 최고의 성능과 안정성 있는 웹 서버 프레임워크라 할 수 있습니다.
https://docs.rs/axum/latest/axum/index.html#example
https://tokio.rs/tokio/tutorial/async
fn main() {
let x = String::from("Hello!");
let y = &x;
println!("{} {}", x, y);
}
어떤 변수의 레퍼런스를 사용해 원래 변수의 값을 바꾸려면 원래 변수를 가변으로 선언해야 한다.
fn dummy(y: &mut String) {
y.push_str(" world!");
println!("{}", y);
}
fn main() {
let mut x = String::from("Hello");
dummy(&mut x);
println!("{}", x);
}
주의) 한 번에 하나의 소유자만 존재할 수 있다. 하나의 소유권을 한 번 이상 대여할 수 없음.
trait Greet {
fn say_hello(&self) {}
}
HTTP(Hypertext Transfer Protocol): API를 사용하고자 하는 클라이언트와 API를 제공하는 서버 간의 통신을 위한 표준화된 통신 규약.
요청 메서드(request method): 클라이언트가 서버에 API를 사용하기 위한 요청을 보낼 때, 어떤 종류의 작업을 요청하는지를 나타내는 방법
요청 본문(request body): 실제 데이터가 담기는 영역
응답 코드(Response code): 서버가 수신한 요청에 대한 처리 결과를 나타내는 미리 약속된 값
JSON(JavaScript Object Notation): 자바스크립트 프로그래밍 언어에서 객체를 표현하는 방식에서 아이디어를 차용한 데이터 표현 방식. 사람이 읽고 쓰기 편리하며, 데이터가 계층화되어 있어 API를 사용할 때 데이터를 주고받는 데 많이 사용한다.
- 키-값 쌍으로 이루어져 있음
- 값: 불리언, 숫자, 문자열, 배열, 다른 JSON
HTTP에 SSL/TSL 암호화 계층이 추가된 것으로, 데이터 보안성이 높다.
소스 코드와 데이터베이스 간의 불일치를 해결하기 위해 사용하는 방법
SQL을 직접 치는 게 아니라, 코드로 작성해서 실행함.
1) 여러 개발자/서버에서 동일하게 적용
2) 변경 내역이 명확하게 기록됨
3) 롤백이 쉬움(migrate down)
4) 코드와 DB의 연결이 자연스럽다
단점: 문법 공부, SQL의 일부 복잡한 기능은 코드로 표현하기 어려움.
https://www.sea-ql.org/SeaORM/
현재 실습하고 있는 내용들을 github에 업로드 하고 있다.
그냥 디렉토리 작업한 것을 모두 push했더니 챕터 3에 해당하는 것은 업로드가 되지 않는다.
rust는 빌드할 때마다 모든 바이너리/라이브러리/테스트/디버깅 정보를 target 폴더에 생성. 즉, 대규모 의존성 + 빌드 캐시가 모두 저장되고 있는데 이 용량이 만만치 않은 것.
현재 디렉토리가 6개정도 있는데, 모두 각각의 프로젝트인 상황.
.gitignore로 target관리를 해야 한다.
1) 모든 커밋 히스토리에서 /target/폴더 완전 제거
git filter-branch --force --index-filter \
"git rm -r --cached --ignore-unmatch target migration/target */target" \
--prune-empty --tag-name-filter cat -- --all
2) 불필요한 데이터 정리
git reflog expire --expire=now --all
git gc --prune=now --aggressive
3) 강제 푸시
git push --force --all
git push --force --tags
특정 디렉토리 용량 확인
du -sh <디렉토리명>
- -s: 총합 summary
- -h: human-readable
현재 작업중인 rust 폴더의 용량이 2.4GB이다..
와 C언어랑은 차원이 다르구나! 허허