From 5ec0b66775ec349f28a4c58834cd5268a2f90262 Mon Sep 17 00:00:00 2001 From: Ian Rash Date: Thu, 14 Nov 2024 10:56:29 -0800 Subject: [PATCH 1/2] 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 From 7906a8e35549e8ba3d424729f4005779d6bc4b63 Mon Sep 17 00:00:00 2001 From: Ian Rash Date: Thu, 14 Nov 2024 17:38:18 -0800 Subject: [PATCH 2/2] Update docs/syntax_and_semantics/c_bindings/struct.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Johannes Müller --- docs/syntax_and_semantics/c_bindings/struct.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax_and_semantics/c_bindings/struct.md b/docs/syntax_and_semantics/c_bindings/struct.md index 4c8961b08..c35c67f46 100644 --- a/docs/syntax_and_semantics/c_bindings/struct.md +++ b/docs/syntax_and_semantics/c_bindings/struct.md @@ -41,7 +41,7 @@ lib C end ``` -Structs that are defined inside a `lib` can be included as modules internally in other `lib` defined structs, for example: +Structs that are defined inside a `lib` can be included, like modules, internally in other `lib` defined structs, for example: ```crystal lib Lib