import class Range from range; import fn { range, iterator, next, is_consumed } from range; interface Serializable { fn serialize(serializer: @'Serializer, obj: Self) -> String; } // This is a stub class JSONSerializer {} fn serialize(serializer: @JSONSerializer, obj: Int) -> String { return obj.deref().to_string(); } fn serialize(serializer: @JSONSerializer, obj: Float) -> String { return obj.deref().to_string(); } fn serialize(serializer: @JSONSerializer, obj: String) -> String { return "\"" + obj + "\""; } fn serialize_map_field(serializer: @JSONSerializer, key: 'K [Serializable], value: 'V [Serializable]) -> String { return serializer.serialize(*key) + ": " + serializer.serialize(*value); } fn serialize(serializer: @JSONSerializer, obj: Array<'T [Serializable]>) -> String { let res = "["; for i in range(0, obj.len()) { res = res + serializer.serialize(*obj[*i]); if i < obj.len() - 1 { res = res + ", "; } } return res + "]"; } // Implementations implement Serializable for Int; implement Serializable for Float; implement Serializable for String; implement Serializable for Array<'T [Serializable]>;