PostgreSQL Type | PostgreSQL Size | Description | Range | Diesel Type | Rust Type |
---|---|---|---|---|---|
Nullable Types | nullable | Nullable `` |
PostgreSQL Type | PostgreSQL Size | Description | Range | Diesel Type | Rust Type |
---|---|---|---|---|---|
Nullable Types | nullable | Nullable `` |
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
impl From<(PartialUser, UserEntry, &str)> for AuthorizedUser { | |
fn from((user, entry, jwt_token): (PartialUser, UserEntry, &str)) -> Self { | |
let join_names_fn = | |
|first_name: Option<String>, middle_name: Option<String>, last_name: Option<String>| { | |
let names = [first_name, middle_name, last_name]; | |
names | |
.iter() | |
.filter_map(|name| name.as_ref()) | |
.map(|name| name.to_string()) | |
.collect::<Vec<String>>() |
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
use std::pin::Pin; | |
use std::future::Future; | |
async fn async_fn() -> u32 { | |
42 | |
} | |
fn main() { | |
let future = Box::pin(async_fn()); | |
let pinned_future: Pin<Box<dyn Future<Output = u32>>> = future; |
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 quicksort(arr: &mut [i32]) { | |
if arr.len() <= 1 { | |
return; | |
} | |
let pivot = arr[arr.len() - 1]; | |
let mut i = 0; | |
for j in 0..arr.len() - 1 { | |
if arr[j] < pivot { | |
arr.swap(i, j); | |
i += 1; |
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
enum Error { | |
recordNotFound, | |
notValidId, | |
} | |
class Result<T, E> { | |
T? value; | |
E? error; | |
Result.Ok(T value) { |
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
use std::cmp::Ordering; | |
pub fn binary_search(arr: &[i32], value: i32) -> Option<usize> { | |
let mut mid; | |
let mut low = 0; | |
let high = arr.len(); | |
while low <= high { | |
mid = low + (high - low) / 2; | |
match arr.get(mid) { | |
Some(arr_value) => match value.cmp(&arr_value) { |
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
def multiplication(a,b) | |
m = {} | |
while a >= 1 | |
m[a] = b | |
a = a / 2 | |
b = b * 2 | |
end | |
m.select { |k, _| k % 2 != 0 }.values.sum | |
end |
For example, an array [10,20,30,40,50,60] rotate by 2 positions to [30,40,50,60,10,20]
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
struct Solution; | |
impl Solution { | |
fn new() -> Solution { Self } | |
fn binary_search(&self, arr: &[i32], n: usize, k: i32) -> i32 { | |
let mut low = 0; | |
let mut high = n - 1; | |
while low <= high { | |
let mid = low + (high - low) / 2; |
NewerOlder