From 5ec0b66775ec349f28a4c58834cd5268a2f90262 Mon Sep 17 00:00:00 2001 From: Ian Rash Date: Thu, 14 Nov 2024 10:56:29 -0800 Subject: [PATCH] Add `include` info to c-binding's `struct` --- docs/syntax_and_semantics/c_bindings/struct.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/syntax_and_semantics/c_bindings/struct.md b/docs/syntax_and_semantics/c_bindings/struct.md index 90ed9a1bd..4c8961b08 100644 --- a/docs/syntax_and_semantics/c_bindings/struct.md +++ b/docs/syntax_and_semantics/c_bindings/struct.md @@ -41,6 +41,24 @@ lib C end ``` +Structs that are defined inside a `lib` can be included as modules internally in other `lib` defined structs, for example: + +```crystal +lib Lib + struct Foo + x : Int32 + y : Int16 + end + + struct Bar + include Foo + z : Int8 + end +end + +Lib::Bar.new # => Lib::Bar(@x=0, @y=0, @z=0) +``` + To create an instance of a struct use `new`: ```crystal