Generics provide a method for creating functions and composite types that work across a wide range (read: all other) of types.
An example of a type definition using generics is the Option
type:
type Option<T> enum {
None,
Some(T)
};
// 1: Only my crate can implement *and* use it (plain visibilty) | |
pub(crate) trait AllocImpl {} | |
// 2: Only my module can implement the trait, others can use it | |
mod private { | |
pub trait Sealed {} | |
} | |
pub trait AllocImpl: private::Sealed {} |
macro_rules! inner_ptr { | |
($gpuva:expr, $($f:tt)*) 0> ({ | |
fn uninit_from<T: GPUStruct>(_: &GPUWeakPointer<T>) -> MaybeUninit<T::Raw<'static>> { | |
core::mem::MaybeUninit::uninit() | |
} | |
let tmp = uninit_from($gpuva); | |
// ... All the stuff up to and including `inner.offset_from(...)` | |
let off = inner.offset_from(...); | |
let outer = tmp.as_ptr(); | |
fn out_from<T: GPUStruct, U>(gpuva: &GPUWeakPointer<T>) -> GPUWeakPointer<U> { |
upstream myapp { | |
server 127.0.0.1:8081; | |
} | |
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s; | |
server { | |
listen 443 ssl spdy; | |
server_name _; | |
public class Fibo | |
{ | |
public static int fib(int n) { | |
State[] sss = new State[]{ | |
(l) -> new int[]{ l[0], l[1], l[2], l[3], 0}, | |
(l) -> new int[]{ l[0], l[1], l[3]>0?l[3]!=0?l[3]!=1?6:5:4:3, l[3], l[4]}, | |
(l) -> new int[]{ l[0], l[1], l[3]>0?6:0, l[3], l[4]}, | |
(l) -> new int[]{ -1, l[1], 0, l[3], l[4]}, | |
(l) -> new int[]{ 0, l[1], 0, l[3], l[4]}, | |
(l) -> new int[]{ 1, l[1], 0, l[3], l[4]}, |
Rough sketch follows.
To prevent the issue, from C++ style operator overloading, of an operator having to be defined on each type involved in th operation, we use based on the syntax for function declarations. This will allow independent definition without any duplication.
operator +(a: Vector2, b: Vector2): Vector2 {
...
#!/bin/bash | |
# variables | |
export GOPATH=$HOME/ark_go | |
# functions | |
info() { | |
echo "[ ] $@" | |
} |
// History : Event[] | |
// Event : Time|Period, (Person|Object)[], Action[] | |
// Time : basic | |
// Period : Time, Time | |
// | |
use std::io; | |
enum LoopAction<'a> { |
LZO_PUBLIC(int) | |
lzo1_decompress ( const lzo_bytep in , lzo_uint in_len, | |
lzo_bytep out, lzo_uintp out_len, | |
lzo_voidp wrkmem ) | |
{ | |
lzo_bytep op; | |
const lzo_bytep ip; | |
const lzo_bytep const ip_end = in + in_len; | |
lzo_uint t; |
package main | |
import ( | |
"github.com/go-gl/gl" | |
glfw "github.com/go-gl/glfw3" | |
"github.com/kiljacken/gogame" | |
"github.com/kiljacken/gogame/math" | |
"log" | |
) |