rust13 [Python] FFI with Rust 이번 포스팅에서는 Rust로 작성한 코드를 Python에서 사용하는 방법에 대해 설명하겠습니다.Install maturin/PyO3먼저, python 가상 환경을 만들고 rust로작성한 코드를 python package로 빌드할 수 있는 tool을 설치해 줍니다.$ pip install maturinCreate Project다음으로 설치한 tool을 사용하여 프로젝트를 생성합니다.다음 명령을 입력하면 PyO3를 빌드 시스템으로 하는 프로젝트를 생성합니다. $ maturin init -b pyo3Implement Library Crate이제 원하는 rust 코드를 작성합니다.use pyo3::prelude::*;use std::fs::File;use std::io::{Read};#[pyfunction]fn.. 2024. 7. 22. [Tauri] Getting Started with Next.js 데스크톱 앱을 next.js로 만들어 볼까 하는 데, Tauri도 어느정도 더 발전했을 것 같아서 시도를 해보았습니다. ^^ 우선 기본적인 프로젝트 생성 방법을 살펴보겠습니다. 기존 포스팅들도 있고 하니 기본적인 개발환경 구성은 되어 있다고 생각하겠습니다. ^^;; 제가 사용한 rustc 버전은 1.75.0입니다. Create Frontend Project 먼저, frontend로 사용할 Next.js 프로젝트를 생성해 줍니다. $ npx create-next-app@latest --use-npm 원하는 정보를 입력해 줍니다. Configure Frontend 생성된 폴더 내에서 tsconfig.json 파일을 찾아 다음과 같이 설정을 추가해 줍니다. "exclude": [ "node_modules", .. 2024. 1. 25. [Tauri] Getting Started with SvelteKit TAURI는 cross-platform application을 개발할 수 있는 Rust 기반의 framework 입니다. 기존의 electron.js나 nw.js 대비 최적화, 보안성, frontend 독립성에 있어 더 낫고 가볍고 빠르다고 합니다. Prerequisite Rust가 설치가 되어 있어야 합니다. 저는 MAC에서 사용하고 있습니다. 이 포스팅에 사용된 버전은 다음과 같습니다. Rust v1.64.0 node.js v18.12.1 yarn v3.3.0 Create an Application using Cargo Tauri application은 create-tauri-app이라는 유틸리티를 사용하여 만듭니다. $ cargo install create-tauri-app $ cargo creat.. 2022. 11. 24. [Rust] Trait A trait defines functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We can use trait bounds to specify that a generic type can be any type that has certain behavior. Define Trait Trait definitions are a way to group method signatures together to define a set of behaviors necessary to accomplish some purpose. Traits c.. 2022. 8. 8. [Rust] Enums Enums allow us to define a type by enumerating its possible variant. Define Enums Enums are one of the ways to define custom data types. enum Fruits { Apple, Banana, Cherry, } We use the enum keyword to define enums. Values of Enums We can create instances of enums like this. let apple = Fruits::Apple; let banana = Fruirs::Banana; The enum variants are namespaced under its identifier, and we use.. 2022. 8. 6. [Rust] Struct A struct is a custom data type that lets you package together and name multiple related values that make up a meaningful group. Create Struct We define a struct using the struct keyword. And inside curly brackets, we define the names and types of fields. struct Person { name: String, age: u8, } Instantiate Struct We create an instance of that struct by specifying concrete values for each of the .. 2022. 8. 4. [Rust] List with Vector Vector is a collection type and allows us to store more than one value in a single data structure that puts all the values next to each other in memory. Vectors can only store values of the same type. Create Vector To create a vector, we can use Vec::new() function or vec! macro. If we create a vector with an initial value, Rust will infer the type of value. let v: Vec = Vec::new(); let v = vec!.. 2022. 8. 2. [Rust] Function Rust's function is the same as other languages. The main() function is the most important function and it is the entry point of programs. Define Function fn keyword allows us to declare new functions. The naming convention of the function is snake case. fn main() { println!("main() function"); test(); } fn test() { println!("test() function"); } Parameters and Return Values We can define functio.. 2022. 8. 1. [Rust] Control Flow If you have studied other languages, you can use it almost similarly. if Expression if expression allows us to branch code depending on conditions. fn main() { let number = 3; if number == 1 { println!("Number is 1"); } else if number == 2 { println!("Number is 2"); } else { println!("Large number!"); } } The condition in if expression must be a boolean type. In other words, Rust doesn't have tr.. 2022. 7. 31. [Rust] Operator Below are the operators in Rust. Macro Explanation Usage ! Macro expansion ident!(...) ident!{…} ident![…] == Equality comparison expr == expr ≠ Nonequality comparison var ≠ expr Greater than comparison expr > expr ≥ Greater than or equal to comparison expr ≥ expr + Arithmetic addition expr + expr += Arithmetic addition and assignment var += expr - Arithmetic negation -expr - Arithmetic subtract.. 2022. 7. 30. [Rust] Data Type Rust is a statically typed language, meaning it must know all variables' types at compile time. Every value in Rust is of a particular data type. Rust's data types can be roughly divided into two types, which are scalar and compound. If we omit explicit data types, the compiler infers it. Scalar Type A scalar type represents a single value. Integer Type There are signed integers and unsigned int.. 2022. 7. 30. [Rust] Variables Rust's naming convention for variables is the same as other languages. It can have the alphabet, number, and underscore, and can't start with numbers. Immutable Variable Variables are declared using the let keyword and by default it is immutable. fn main() { let x = 1; x = 2; // error[E0384]: cannot assign twice to immutable variable } Mutable Variable Using the mut keyword to make variables mut.. 2022. 7. 28. 이전 1 2 다음