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
| mod traits { | |
| use super::*; | |
| // optionally seal this trait, and that this diagnostic message sometimes | |
| // fail to trigger. | |
| #[diagnostic::on_unimplemented( | |
| label = "incomplete `Conf`", | |
| note = "ensure that `.app()`, `.shell()`, and `.state()` are provided \ | |
| with the required values" | |
| )] |
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 anyhow; // 1.0.95 | |
| use reqwest::ClientBuilder; // 0.12.12 | |
| use std::{collections::BTreeMap, time::Duration, env}; | |
| use tokio::{ | |
| self, | |
| io::{self, AsyncWriteExt} | |
| }; // 1.43.0 | |
| #[tokio::main] | |
| async fn main() -> anyhow::Result<()> { |
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 leptos::prelude::*; | |
| use leptos_meta::{MetaTags, *}; | |
| use leptos_router::{ | |
| components::{A, Routes, Route, Router, ParentRoute}, | |
| hooks::use_params, | |
| nested_router::Outlet, | |
| params::Params, | |
| path, | |
| SsrMode, | |
| StaticSegment, |
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
| /* | |
| [dependencies] | |
| chrono = "0.4.26" | |
| */ | |
| use crate::demo::in_the_future; | |
| pub fn main() { | |
| let dt = chrono::Utc::now(); | |
| println!("{dt} is in the future: {}", in_the_future(dt)); | |
| } |
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
| # This is the complete code for the StackOverflow answer: | |
| # https://stackoverflow.com/a/24947583 | |
| from typing import List | |
| from typing import Literal | |
| from typing import get_args | |
| from sqlalchemy import Enum | |
| from sqlalchemy import ForeignKey | |
| from sqlalchemy import String | |
| from sqlalchemy import and_ | |
| from sqlalchemy import create_engine |
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
| # Complete code for the answer at https://stackoverflow.com/a/67578848 | |
| from sqlalchemy import ForeignKey, String | |
| from sqlalchemy import create_engine, select | |
| from sqlalchemy.orm import DeclarativeBase, Mapped, Session | |
| from sqlalchemy.orm import mapped_column, relationship | |
| from sqlalchemy.orm import contains_eager | |
| class Base(DeclarativeBase): | |
| pass |
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
| // Compare between | |
| // https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=74eaa1906a58b5daad47c210241143a6 | |
| // and | |
| // https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=74eaa1906a58b5daad47c210241143a6 | |
| struct Thing(String); | |
| struct View<'a>(&'a str); | |
| impl<'a> From<&'a Thing> for View<'a> | |
| { |
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::collections::HashMap; | |
| struct ListOfUsers(Vec<(String, String)>); // (User, Email) | |
| struct UserToEmail<'a>(HashMap<&'a str, &'a str>); | |
| struct EmailToUser<'a>(HashMap<&'a str, &'a str>); | |
| impl<'a> From<&'a ListOfUsers> for UserToEmail<'a> { | |
| fn from(value: &'a ListOfUsers) -> Self { | |
| Self(value.0.iter() | |
| .map(|(u, e)| (u.as_ref(), e.as_ref())) |
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
| #[derive(Debug)] | |
| struct EmailAddr(String); // e.g. user@example.com | |
| #[derive(Debug)] | |
| struct Domain<'a>(&'a str); // a slice onward from the @ symbol of the above | |
| impl<'a> From<&'a EmailAddr> for Domain<'a> { | |
| fn from(value: &'a EmailAddr) -> Self { | |
| Self(&value.0[value.0.find('@').unwrap_or(0)..]) | |
| } | |
| } |
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
| # pip install SQLAlchemy==2.0.12 psycopg2==2.9.6 | |
| import random | |
| from sqlalchemy import Column, Integer, String | |
| from sqlalchemy import create_engine | |
| from sqlalchemy import select | |
| from sqlalchemy.orm import declarative_base, sessionmaker, scoped_session | |
| Base = declarative_base() | |
| class Entity(Base): |
NewerOlder