Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
2,478 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Automatically generated by Diplomat | ||
|
||
#pragma warning disable 0105 | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using DiplomatFeatures.Diplomat; | ||
#pragma warning restore 0105 | ||
|
||
namespace DiplomatFeatures; | ||
|
||
#nullable enable | ||
|
||
public partial class CountedOpaque: IDisposable | ||
{ | ||
private unsafe Raw.CountedOpaque* _inner; | ||
|
||
/// <summary> | ||
/// Creates a managed <c>CountedOpaque</c> from a raw handle. | ||
/// </summary> | ||
/// <remarks> | ||
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). | ||
/// </remarks> | ||
/// <remarks> | ||
/// This constructor assumes the raw struct is allocated on Rust side. | ||
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction. | ||
/// </remarks> | ||
public unsafe CountedOpaque(Raw.CountedOpaque* handle) | ||
{ | ||
_inner = handle; | ||
} | ||
|
||
/// <returns> | ||
/// A <c>CountedOpaque</c> allocated on Rust side. | ||
/// If a custom Drop implementation is implemented on Rust side, it WILL run on destruction. | ||
/// </returns> | ||
public static CountedOpaque New(Counter counter) | ||
{ | ||
unsafe | ||
{ | ||
Raw.Counter* counterRaw; | ||
counterRaw = counter.AsFFI(); | ||
if (counterRaw == null) | ||
{ | ||
throw new ObjectDisposedException("Counter"); | ||
} | ||
Raw.CountedOpaque* retVal = Raw.CountedOpaque.New(counterRaw); | ||
return new CountedOpaque(retVal); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns the underlying raw handle. | ||
/// </summary> | ||
public unsafe Raw.CountedOpaque* AsFFI() | ||
{ | ||
return _inner; | ||
} | ||
|
||
/// <summary> | ||
/// Marks this object as moved into Rust side. | ||
/// </summary> | ||
public void MarkAsMoved() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
throw new ObjectDisposedException("CountedOpaque"); | ||
} | ||
_inner = null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Restores unmanaged ressource handle to this object. | ||
/// </summary> | ||
public unsafe void RestoreHandle(Raw.CountedOpaque* handle) | ||
{ | ||
_inner = handle; | ||
} | ||
|
||
/// <summary> | ||
/// Destroys the underlying object immediately. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
return; | ||
} | ||
|
||
Raw.CountedOpaque.Destroy(_inner); | ||
_inner = null; | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
|
||
~CountedOpaque() | ||
{ | ||
Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Automatically generated by Diplomat | ||
|
||
#pragma warning disable 0105 | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using DiplomatFeatures.Diplomat; | ||
#pragma warning restore 0105 | ||
|
||
namespace DiplomatFeatures; | ||
|
||
#nullable enable | ||
|
||
/// <summary> | ||
/// Counts how many distinct `CountedOpaque` objects are instanciated | ||
/// </summary> | ||
public partial class Counter: IDisposable | ||
{ | ||
private unsafe Raw.Counter* _inner; | ||
|
||
/// <summary> | ||
/// Creates a managed <c>Counter</c> from a raw handle. | ||
/// </summary> | ||
/// <remarks> | ||
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). | ||
/// </remarks> | ||
/// <remarks> | ||
/// This constructor assumes the raw struct is allocated on Rust side. | ||
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction. | ||
/// </remarks> | ||
public unsafe Counter(Raw.Counter* handle) | ||
{ | ||
_inner = handle; | ||
} | ||
|
||
/// <returns> | ||
/// A <c>Counter</c> allocated on Rust side. | ||
/// If a custom Drop implementation is implemented on Rust side, it WILL run on destruction. | ||
/// </returns> | ||
public static Counter New() | ||
{ | ||
unsafe | ||
{ | ||
Raw.Counter* retVal = Raw.Counter.New(); | ||
return new Counter(retVal); | ||
} | ||
} | ||
|
||
public nuint Count() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
throw new ObjectDisposedException("Counter"); | ||
} | ||
nuint retVal = Raw.Counter.Count(_inner); | ||
return retVal; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns the underlying raw handle. | ||
/// </summary> | ||
public unsafe Raw.Counter* AsFFI() | ||
{ | ||
return _inner; | ||
} | ||
|
||
/// <summary> | ||
/// Marks this object as moved into Rust side. | ||
/// </summary> | ||
public void MarkAsMoved() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
throw new ObjectDisposedException("Counter"); | ||
} | ||
_inner = null; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Restores unmanaged ressource handle to this object. | ||
/// </summary> | ||
public unsafe void RestoreHandle(Raw.Counter* handle) | ||
{ | ||
_inner = handle; | ||
} | ||
|
||
/// <summary> | ||
/// Destroys the underlying object immediately. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
return; | ||
} | ||
|
||
Raw.Counter.Destroy(_inner); | ||
_inner = null; | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
|
||
~Counter() | ||
{ | ||
Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.