Skip to content

Instantly share code, notes, and snippets.

View giacomorebecchi's full-sized avatar
🖥️

Giacomo Rebecchi giacomorebecchi

🖥️
View GitHub Profile
@giacomorebecchi
giacomorebecchi / pydantic_url.py
Created March 6, 2024 13:57
Pydantic v2-compatible Url, based on the behaviour of the v1 version
from typing import Any, Optional
from urllib.parse import parse_qs, unquote
from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
from pydantic import v1 as pydantic_v1
from pydantic_core import CoreSchema, core_schema
from typing_extensions import Self
class Url(pydantic_v1.AnyUrl):
// An attribute to hide warnings for unused code.
#![allow(dead_code)]
#[derive(Debug)]
struct Person {
name: String,
age: u8,
}
// A unit struct
use std::fmt;
// Tuples can be used as function arguments and as return values.
fn reverse(pair: (i32, bool)) -> (bool, i32) {
// `let` can be used to bind the members of a tuple to variables.
let (int_param, bool_param) = pair;
(bool_param, int_param)
}