This file contains 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
// Accepts any type T as its argument which satisfies 'static lifetime trait bounds. | |
fn generic<T: 'static>(v: T) {} | |
// 1. No references. | |
struct NoReferences(String); | |
// 2. Includes a 'static lifetime reference. | |
struct IncludesStaticRef(&'static str); | |
// 3. Inclues a lifetime reference named 'a |
This file contains 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 generic<T>(x: T) where T: 'static { ... } |
This file contains 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 x: &'static str = "Hello, world."; |
This file contains 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
#![feature(prelude_import)] | |
#[prelude_import] | |
use std::prelude::rust_2021::*; | |
#[macro_use] | |
extern crate std; | |
use pyo3::prelude::*; | |
/// Formats the sum of two numbers as string. | |
fn sum_as_string(a: usize, b: usize) -> PyResult<String> { | |
Ok((a + b).to_string()) | |
} |
This file contains 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
use pyo3::prelude::*; | |
/// Formats the sum of two numbers as string. | |
#[pyfunction] | |
fn sum_as_string(a: usize, b: usize) -> PyResult<String> { | |
Ok((a + b).to_string()) | |
} | |
/// A Python module implemented in Rust. | |
#[pymodule] |
This file contains 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
[build-system] | |
requires = ["maturin>=1.0,<2.0"] | |
build-backend = "maturin" | |
[project] | |
name = "my-first-pyo3" | |
requires-python = ">=3.7" | |
classifiers = [ | |
"Programming Language :: Rust", | |
"Programming Language :: Python :: Implementation :: CPython", |
This file contains 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
[package] | |
name = "my-first-pyo3" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[lib] | |
name = "my_first_pyo3" | |
crate-type = ["cdylib"] |
This file contains 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
void a_function(); | |
int main() { | |
a_function(); | |
} |
This file contains 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
#include <stdio.h> | |
void a_function() { | |
printf("This is a_function!\n"); | |
} |
This file contains 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
from time import sleep | |
delta = { | |
1: { | |
0: ( 1, 1, 2), | |
1: ( 2, -1, 1), | |
2: ( 1, -1, 1) | |
}, | |
2: { | |
0: ( 2, -1, 1), |
NewerOlder