Trying to use Mir ion, its a perfect example of the failure of D's attribute system

Kagamin spam at here.lot
Mon Jan 23 09:51:59 UTC 2023


On Thursday, 19 January 2023 at 04:06:27 UTC, A moo person wrote:
> struct PageSerial {
> 	// this is just some GUI element
> 	// the contents of this gui element is what I am trying to 
> ser/deser
> 	private Grid g;
>
> 	@serdeKeys("blocks")
> 	@serdeIgnoreIn
> 	//@serdeLikeList
> 	auto blocks_out() @property @trusted const {
> 		// Had to put @trusted because the mir function to ser/deser 
> is @safe
> 		// Had to put const because the mir function decides to cast 
> my type to const when working with it?? no idea why
>
> 		import std.algorithm : filter, map;
> 		import std.range : ElementType;
> 		// have to cast away the const
> 		auto t = cast(PageSerial*)(&this);
> 		auto r =
> 			(t.g).contents.children()[]
> 			.filter!(c => (cast(GridBlock)c !is null))()
> 			.map!(c => GridBlockSerial(cast(GridBlock)c))();
> 		static assert(is(ElementType!(typeof(r)) == GridBlockSerial));

Not every type can be serialized, normally you serialize a DTO - 
a type designed for serialization and holds primitive or simple 
data, then it will be compatible with attributes.


More information about the Digitalmars-d mailing list