golang에서는 비트 구조체 안되던것 같은데 러스트에서는 된다고 하니 관심이 증가중 ㅋㅋ
머 리눅스 커널에서도 쓰려고 하는데 설마 없겠어? 싶기도 하네
use bit_struct::*;
enums! {
// 2 bits, i.e., 0b00, 0b01, 0b10
pub HouseKind { Urban, Suburban, Rural}
}
bit_struct! {
// u8 is the base storage type. This can be any multiple of 8
pub struct HouseConfig(u8) {
// 2 bits
kind: HouseKind,
// two's compliment 3-bit signed number
lowest_floor: i3,
// 2 bit unsigned number
highest_floor: u2,
}
}
// We can create a new `HouseConfig` like such:
// where all numbers are statically checked to be in bounds.
let config = HouseConfig::new(HouseKind::Suburban, i3!(-2), u2!(1));
// We can get the raw `u8` which represents `config`:
let raw: u8 = config.raw();
assert_eq!(114_u8, raw);
// or we can get a `HouseConfig` from a `u8` like:
let mut config: HouseConfig = HouseConfig::try_from(114_u8).unwrap();
assert_eq!(config, HouseConfig::new(HouseKind::Suburban, i3!(-2), u2!(1)));
// We need to unwrap because `HouseConfig` is not valid for all numbers. For instance, if the
// most significant bits are `0b11`, it encodes an invalid `HouseKind`. However,
// if all elements of a struct are always valid (suppose we removed the `kind` field), the struct will
// auto implement a trait which allows calling the non-panicking:
// let config: HouseConfig = HouseConfig::exact_from(123_u8);
// We can access values of `config` like so:
let kind: HouseKind = config.kind().get();
// And we can set values like so:
config.lowest_floor().set(i3!(0));
// We can also convert the new numeric types for alternate bit-widths into the
// numeric types provided by the standard library:
let lowest_floor: i3 = config.lowest_floor().get();
let lowest_floor_std: i8 = lowest_floor.value();
assert_eq!(lowest_floor_std, 0_i8);
def http_error(status): match status: case 400: return "Bad request" case 404: return "Not found" case 418: return "I'm a teapot" case _: return "Something's wrong with the internet" Note the last block: the “variable name” _ acts as a wildcard and never fails to match. If no case matches, none of the branches is executed.
You can combine several literals in a single pattern using | (“or”):
case 401 | 403 | 404: return "Not allowed"
class Point: x: int y: int
def where_is(point): match point: case Point(x=0, y=0): print("Origin") case Point(x=0, y=y): print(f"Y={y}") case Point(x=x, y=0): print(f"X={x}") case Point(): print("Somewhere else") case _: print("Not a point")
PEP 636 – Structural Pattern Matching: Tutorial Author: Daniel F Moisset <dfmoisset at gmail.com> Sponsor: Guido van Rossum <guido at python.org> BDFL-Delegate: Discussions-To: Python-Dev list Status: Final Type: Informational Created: 12-Sep-2020 Python-Version: 3.10 Post-History: 22-Oct-2020, 08-Feb-2021 Resolution: Python-Committers message
PEP 3103 – A Switch/Case Statement Author:Guido van Rossum <guido at python.org> Status:Rejected Type:Standards Track Created:25-Jun-2006 Python-Version:3.0 Post-History:26-Jun-2006
Flask 에 static_url_path와 static_folder 를 설정해서 정적으로 서빙할 경로를 지정한다.
template_folder는 template engine를 위한 경로 같긴한데, 지금은 그걸 하려는게 아니니 패스~ 하고
/ 로 요청이 들어오면 index.html을 던지도록 라우터 하나 설정하고
나머지는 자동으로 static 경로 하위에서 제공
그리고 /api 쪽은 별도로 라우터 지정해서 2개의 api를 생성해준다.
/app.py
from flask import Flask, jsonify, render_template
app = Flask(__name__,
static_url_path='',
static_folder='static',
template_folder='templates')
@app.route('/')
def serve_index():
return app.send_static_file('index.html')
# REST API 라우트
@app.route('/api/hello')
def api_hello():
return jsonify({"message": "Hello, this is a REST API response!"})
# 또 다른 REST API
@app.route('/api/sum/<int:a>/<int:b>')
def api_sum(a, b):
return jsonify({"a": a, "b": b, "sum": a + b})
if __name__ == "__main__":
# 디버그 모드 실행
app.run(debug=True)
$ python3 app.py * Serving Flask app 'app' * Debug mode: on WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://127.0.0.1:5000 Press CTRL+C to quit * Restarting with stat * Debugger is active! * Debugger PIN: 997-788-229
-O2 밖에 안되서 어떻게 될지 모르겠지만 혹시나 cython 이라던가 이쪽에서 지원하지 않을가 해서 검색해보니
먼가 하나 나와서 테스트 중
설치는 간단하고
# pip3 install simsimd Collecting simsimd Downloading simsimd-6.5.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.metadata (70 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 70.5/70.5 kB 758.3 kB/s eta 0:00:00 Downloading simsimd-6.5.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (563 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 563.2/563.2 kB 4.6 MB/s eta 0:00:00 Installing collected packages: simsimd Successfully installed simsimd-6.5.1 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv